ListBox with nothing selected shows highlighted entry

450 Views Asked by At

My ListBox is set to SelectionMode=MultiSimple. It starts life with nothing selected, and nothing highlighted. If I then select an entry (other than the top-most one), it selects the item, and highlights it. If I then select the same entry again, it de-selects it, and the SelectedXxxx values all indicate that nothing is selected, but the topmost line is now highlighted in error. What is going wrong, and how do I fix it? Thanks

2

There are 2 best solutions below

0
On

The first item in a list box or dropdown combo box is ID 0. You should set the list box selection index to -1 to make sure nothing is selected or highlighted. Setting it to 0 sets the list box (or comb box) to select the first item.

0
On

Ok, I've found a solution. I test to see that the selected index is -1, and when it is I set it to 0 then back to -1 again. This clears the unwanted highlight on row 0.