ListBox crash when accessing SelectedIndex

V

Valerie Hough

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
 
D

David Ching

Valerie Hough said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top