I am trying to capture all rows selected in my listbox and I have this code that works well (listbox.cellclick) event HOWEVER it is a click behind. Is there something I can do differently in my code to get the selection only on the first mouse click?
Example:
Click on Two Rows
DEbug Pops up and shows my array at -1
Press Play on IDE
Click the SAME two rows
Debug shows my array now having the correct rows that were selected…But I had to click two separate times to get it.
for i as integer = 0 to Me.ListCount-1
if me.Selected(i) Then
SelectedRows.Append i
End if
Next i
I have tried this code slightly modified in the Window’s Mouse UP event and Mouse Down event with no success.
CellClick happens BEFORE the selection is changed. Use the Row parameter to update your array. Or you might be able to use the Change event, although it fires more often than you might want.
[quote=160403:@Roger Jönsson]Using the Change Event solved it for me also. Good.
May I ask, why the MouseUp event also seems to be one click behind?
MouseUp happens after MouseDown etc… -At least from the operators’ side of things.[/quote]
Not sure I understand you concern? Of course MouseUp happens after MouseDown… how could it not?
But ONLY if you return TRUE from the MouseDown (otherwise UP never fires at all)
I tried to read a Listboxs’ Listindex, by clicking on a row in it (and then use the listindex to get the data from the row I clicked on).
I couldn’t do this with mousedown and I couldn’t do this with mouse up. I figured that the mouse up would happen so late, that it should not be a problem getting the current listindex (if mouse down was too early to get it). Whatever I did I got the previous listindex. I guessed that it might have to do with timing, but that was obviously not it.
So the question is: Why do I get the previous listindex with mousedown or mouseup etc (not knowing why, it seems not so logical)?
Changes are processed after MouseUp, not MouseDown. That gives the user the chance to cancel his action by moving the mouse off the control before releasing it. This is universal and expected behavior.