Unselect a Selected Row in WebListbox

I have rescued a topic that Robert Livingston asked in 2021 (for a listbox, here) and to which I can’t find a solution in 2024 for the Weblistbox.

I allow myself to copy exactly Robert’s question because the problem is the same but for the Weblistbox element:

Is there a solution? Any suggestions @Ricardo_Cruz ?

Thank you very much in advance.

Best regards,
Sergio

Programmatically, you can do this by setting the SelectedRowIndex to -1:

Listbox1.SelectedRowIndex = -1

For the user to accomplish it, you’d probably need to use the Pressed event to compare the SelectedRowIndex to the Row parameter to implement a toggle.

To implement this, I added the following property to the page:

Private Property selectedIndex As Integer = -1

Then, in the WebListBox’s Pressed event:

if selectedIndex = -1 or selectedIndex <> row then
  selectedIndex = row
else
  if me.SelectedRowIndex = selectedIndex then
    me.SelectedRowIndex = -1
    selectedIndex = -1
  end if
end if

This implements a toggle when the user presses a row. If it’s already selected then it’s deselected.

3 Likes

Thank you very much @Anthony_G_Cyphers ,

It works perfectly, great!

2 Likes