I am seeing the highlighted row number in a listbox being different from the Listbox.SelectedRowIndex.
This is a listbox with less than 10 rows.
The numbers usually match, but clicking one row quickly after clicking another row can leave the SelectedRowIndex unchanged from the previous row’s index.
I included the CellPressed event to the listbox to force the SelectedRowIndex to be correct. CellPressed has always returned the correct row so far.
Function CellPressed(row As Integer, column As Integer, x As Integer, y As Integer) Handles CellPressed as Boolean
If row<>VisitBox.SelectedRowIndex Then
VisitBox.SelectedRowIndex=row
end if
End Function
Is there some caveat to using SelectedRowIndex to test for the index of the highlighted row?
I should have said this is on a Mac and the listbox is in single row selection mode.
I am trying to reproduce this problem in a sample project to post. No success so far.
The macOS mouse double-click speed affects how clicking from row to row is read by Xojo.
Adding this to the listbox CellPressed event forces the SelectedRowIndex to update correctly.
Function CellPressed(row As Integer, column As Integer, x As Integer, y As Integer) Handles CellPressed as Boolean
MyListBox.SelectedRowIndex=row
End Function
You say that quickly clicking to change the selection sometimes leaves SelectedRowIndex lagging behind. Where in your code are you accessing this property?
The property MyListBox.SelectedRowIndex was examined in the MyListBox.SelectionChanged event. I could press between the up and down arrows as fast as I could and the MyListBox.SelectedRowIndex would always be correct. Relying on the mouse click was iffy. Even though the MyListBox.SelectionChanged event fired, the SelectedRowIndex did not necessarily keep up.
When I set the macOS double-click speed to fast, the problem almost went away, but since user settings can’t be anticipated, it looks like forcing the MyListBox.SelectedRowIndex is a safeguard.
This doesn’t surprise me at all. The problem is in the OS logic that decides whether the click is a double click or not. Typically you don’t want to wait the entire double click period to say that a click has happened, especially for extra long double click periods, so it’s kinda catch 22.