LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to highlight Table Row when clicking on any cell in that row.

I used the postdeferredcallback. It works when you click the cell fast in the 1st column. when you hold the mouse button down alittle bit it does not highlight the rest of the row. in the 2nd column it does highlight the 1st and 2nd column regardless of how i click it. i am using the settableselection function to set the active cell and i use the left_click event!!!! Is there another event firing if you hold the mouse button too long?
0 Kudos
Message 1 of 7
(5,529 Views)
Can you tell us a little bit more about what exactly is failing?

I assume that you are using the deferred callback to obtain the newly activated cell, and you are then setting the selection to be the entire column. Which part of this code is failing? Is it not returning the expected cell, or is the SetTableSelction function not selecting the expected range of cells?

- luis
Message 2 of 7
(5,529 Views)
the settableselection function is not selecting the expected range of cells in the row. if you click it fast then hit works, but if you hold the click alittle bit to long then it only highlights the one cell.
0 Kudos
Message 3 of 7
(5,529 Views)
What's probably happening is that the table is "fighting" you for control of the active cell. When you do a quick click, the control will process the "mouse up" message before your deferred callback has a chance to override the selection. This allows you to have the last say...

However, when you hold down the click for a while, your deferred callback is called while the mouse is still down. Your selection change takes effect immediately but then later on, when the mouse button is released, the table resets the active cell to what it thinks it should be.

One quick-and-dirty thing you can do to overcome this is to wait for the mouse to come up in your deferred callback, instead of setting the selection right away, you should wait until the mo
use button is released:

while (!mouseUp)
{
GetRelativeMouseState (..., &mouseUp,...)
ProcessSystemEvents()
}

Another thing you can do is to "swallow" the left-click event (by returning 1). This prevents the table from processing the mouse click altogether. However, you'd have to convert the mouse position to the table cell yourself, using GetTableCellFromPoint().

- luis
0 Kudos
Message 4 of 7
(5,529 Views)
i tried using the mouse up loop in the deferred callback and it works, except when i click and hold for a second in the first column. this table only has 2 columns. i am attaching the deferred function maybe it will help. thank you for all your help.

Donnie
0 Kudos
Message 5 of 7
(5,529 Views)
I was able to run your code and reproduced the problem you described. There wasn't anything wrong with your code, it's just that, as it turns out, the delay you had wasn't sufficient. The short answer is that you need to shift the while loop to the LEFT_CLICK callback (see attachment).

The long answer is that it became necessary to insert a delay (represented by the deferred callback) between waiting for the mouse to come up and the call to SetTableSelection. Otherwise, when the stack is unwound after the deferred callback, the table is still going to reset the selection to its default setting.
The only reason this worked when you clicked on the second column is because of a side-effect of setting the table selection,
which causes the active cell to be pinned to the new selection range (this happens whenever the active cell lies outside the new selection range; in this case, the active cell becomes the upper-leftmost cell of the range). When the stack is unwound, the new selection is reset to the the cell you clicked on "unioned" with the cell that was made active in SetTableSelection. The end result is that the strategy I had suggested to you would have only worked properly when you clicked on the last column of the table. Sorry about that...

I realize that this process is not as trivial as it should be. Ideally, you would receive a "new active cell" event, which you could then respond to by resetting the selection, without having to deal with deferred callbacks, or anything else of the sort. We have decided, in a future release, to greatly expand the set of events that the more complex controls in the library support, so that something like this can become a lot easier than it is now.

- luis

0 Kudos
Message 6 of 7
(5,529 Views)

Perhaps a simple way to do this would look like this on the Mouse Up event...

Point activeCell;

Rect rowSelect;

 

GetActiveTableCell(panel,control,&activeCell);
GetNumTableColumns(panel,control,&numCols);
rowSelect.top=activeCell.y;
rowSelect.left=1;
rowSelect.height=1;
rowSelect.width=numCols;

SetTableSelection(panel,control,rowSelect );



Message Edited by craige on 12-13-2007 11:59 AM
0 Kudos
Message 7 of 7
(5,123 Views)