This works well on a single selection listbox:
protected override OnMouseDown(...)
{
base.OnMouseDown(...);
MessageBox.Show(this.SelectedIndex.ToString());
}
But on a multiple selection listbox you get a IndexOutOfRange exception.
Which is not documented as a possible exception being thrown by accessing
any of the ListBox properties. Apparently in the OnMouseDown event on a
multiple selection listbox something is in the wrong state and all the
selection properties (SelectedItems, SelectedIndices, SelectedIndex) cannot
be accessed.
Bug or feature?
/Gianluca