Unselect a Selected Row in Listbox

Given the documentation says:

If the DesktopListBox is in multiple-row selection mode, then the number of the lowest selected row is returned.

Then yes, that would work.

1 Like

I wouldnā€™t have posted it if it didnā€™t worked :wink:

Yes, but thereā€™s a difference between it working and it being guaranteed to work in the future. The documentation actually defines the behaviour in multiple selection conditions, which means it is safe for the future. If it hadnā€™t have been defined then it wouldnā€™t be ā€˜safeā€™, even if it did work.

Testing proves that the following works no matter what the selection mode is. However, nothing is said in the documentation that says that is what happens, so would would have to use it with knowledge that it could change in the future.

Listbox1.SelectedRowIndex = -1

or more readble, and avoiding magic numbers:

Listbox1.SelectedRowIndex = DesktopListBox.NoSelection
1 Like