Listbox row

In a non editable listbox, when a change event occurs, I need to know the id of the precedent selected row.

Is there a simple way to get it ?


ListIndex contains the currently selected row. The problem is that it has already changed when the change event is called, so you need to store that info somewhere (eg in a property)

Make a subclass of the ListBox, add two integer properties PreviouslySelectedRow and CurrentlySelectedRow. Both should be -1 to start with.

In the Change event do

PreviouslySelectedRow = CurrentlySelectedRow. // value before row changed

CurrentlySelectedRow = me.ListIndex // current value


I had a working solution, but much less elegant.

Thank you.