I have a Listbox. Row Selection Type is Single.
I select a row by clicking on it. It becomes highlighted.
Now how do I unselect that row? If there are visible blank rows at the end of the Listbox, I can click in that area and achieve the goal. But if there are hundreds of Listbox rows, then it is likely that the blank area at the end of the Listbox will not be visible, and I might have to scroll a long way to get there.
If I click on another row, the original row is unselected but the new row becomes selected. I want to return the state of the Listbox to nothing selected.
If I click on another row, then the behavior is already what I would want. The new row gets selected and the old row gets unselected.
If I click on the same row, I can capture the row in one of the Paint Events, but when I try and take advantage of this, the effect is simply to make it impossible to select any row. I suspect that the Paint event undoes the selection action immediately after it occurs. Here is the code I was trying in the PaintCellText event.
Var theSelectedRow As Integer
theSelectedRow = Me.SelectedRowIndex
If theSelectedRow = row Then
Me.RowSelectedAt(theSelectedRow) = False
End If
I tried this approach and it worked. I put the following in the Pressed event of a button I called Unselect. The Listbox in question is named lbActiveApplescripts
If Self.lbActiveApplescripts.SelectedRowCount = 1 Then
Self.lbActiveApplescripts.RowSelectedAt(Self.lbActiveApplescripts.SelectedRowIndex) = False
End If
While it works, I would prefer not to clutter my UI with this extra button (or menu item if that approach is used). But I can not figure out how to unselect the row by simply clicking on a selected row.
I just checked in a random Xojo project and Command-click on a selected row works as intended (deselects the clicked row).
Tested on a “simple” listbox, with multiple selection allowed.
If it is a list you can only select one Row then “SelectedRowIndex = -1” will do the trick. For multi-select listbox you would likely have to loop through he list and test for “RowSelectedAt( Index ) = True” and set it to false.