Can anyone please tell me how it is possible to get the following crash when
accessing ListBox.SelectedIndex property:
Message: Index was outside the bounds of the array.
Stack Trace:
at System.Windows.Forms.ListBox.ItemArray.GetEntryObject( Int32
virtualIndex, Int32 stateMask)
at System.Windows.Forms.ListBox.get_SelectedIndex()
It is not possible to use the ListBox.SelectedIndex = <some bad value> to
put a bad value in there (I've tried and this causes an immediate
exception),
so I just can't see how the above crash is possible
Can anyone please help?
Thanks in advance,
Valerie Hough
David Ching - 11 Jun 2007 01:29 GMT
> Can anyone please tell me how it is possible to get the following crash
> when accessing ListBox.SelectedIndex property:
>
> Message: Index was outside the bounds of the array.
What was the value of ListBox.SelectedIndex?
Just a guess... when you first init a listbox, I don't think an item is
selected. In Win32 (not .NET), the selected index is -1. So you can't use
that to select an item. I'm not sure this is what is happening here.
-- David