listindex is -1?

For some reason my application began to behave differently after a modification i made to a control on my web page.
I have a class called MyWebListBox which is now derived from WebListBox. (It wasn’t a derived class before)

Prio to me using MyWebListBox I was simply using a WebListBox.
I added the new class to my project and added 1 method to MyWebListBox.
I changed the class type of the WebListBox on the WebPage to be MyWebListBox.
I also changed the property multi-line to true in the IDE.

I ran my application and an exception was thrown due to the fact that ListIndex was now -1 in the SelectionChanged Event.

I thought, “Oh maybe because I changed to multi-line selection that I can’t rely on ListIndex.”. So I changed multiline back to false, ran my app and again I’m getting a -1 for ListIndex.

So… Is this something to do with the fact that I’ve now derived a class from WebListBox?

I’m a bit confused… I thought that the selection changed event should not affected the notion of the ‘current row’…

ListIndex is -1 when there is nothing selected

Interesting… because the exception is thrown when I click on a row of a populated WebListBox.

If there was nothing selected before the click, then remember that the click happens before selection happens.

I see your point… Perhaps I should use the mouse up event and check if listindex changed?

Have you tried using the “SelectionChanged” event?