Question

I seem to be having issues with the selected index on a list box.

The list box is having various items inserted depending on the user selection. An example would be:

LiIndex = ListBox1.Items.Count      
ListBox1.Items.Insert(LiIndex, "Item1")

LiIndex = ListBox1.Items.Count      
ListBox1.Items.Insert(LiIndex, "AND")

LiIndex = ListBox1.Items.Count      
ListBox1.Items.Insert(LiIndex, "Item2")

LiIndex = ListBox1.Items.Count      
ListBox1.Items.Insert(LiIndex, "AND")

LiIndex = ListBox1.Items.Count      
ListBox1.Items.Insert(LiIndex, "Item3")

This all work and displays without a problem. The issue I have is if I select the second of the two AND's. If I click the second "AND" in the list and then a button to fire a method, the selected index is always the index of the first "AND".

Dim listIndex as integer = ListBox1.SelectedIndex

I can't work out why, the listbox itself will always show the second one as selected, but the action will happen against the first one.

Any ideas as to where I am going wrong would be greatly appreciated.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top