M
Marcos Ribeiro
I Have a ListBox that uses an ArrayList with objects as DataSource
The objects are added to the ArrayList using a Database
If I Add/Delete any item on the ListBox, the ArrayList is rebuilt with
something like:
MyArrList.Clear()
MyListBox.DataSource = nothing
...... peek database and ReFill MyArrList with MyObjects
If MyArrList.Count > 0 Then
MyListBox.DataSource = MyArrList
MyListBox.ValueMember = "SomeProperty1"
MyListBox.DisplayMember = "SomeProperty2"
MyListBox.SelectedIndex = 0
End If
Everything works fine if I Add or Delete any Item but the last one on
MyListBox
Debugging: When I delete the last Item the line:
"MyListBox.DisplayMember = "SomeProperty2" doesn't work and DisplayMember
remains = ""
and when I reach the line:
"MyListBox.SelectedIndex = 0" I get an error "Index was out of range"
(Obvious since DisplayMember is empty)
This only happens with the last item
What am I doing wrong?
This is the right way to change a ListBox DataSource (and it´s legal to do
it?)
Thanks
Marcos
The objects are added to the ArrayList using a Database
If I Add/Delete any item on the ListBox, the ArrayList is rebuilt with
something like:
MyArrList.Clear()
MyListBox.DataSource = nothing
...... peek database and ReFill MyArrList with MyObjects
If MyArrList.Count > 0 Then
MyListBox.DataSource = MyArrList
MyListBox.ValueMember = "SomeProperty1"
MyListBox.DisplayMember = "SomeProperty2"
MyListBox.SelectedIndex = 0
End If
Everything works fine if I Add or Delete any Item but the last one on
MyListBox
Debugging: When I delete the last Item the line:
"MyListBox.DisplayMember = "SomeProperty2" doesn't work and DisplayMember
remains = ""
and when I reach the line:
"MyListBox.SelectedIndex = 0" I get an error "Index was out of range"
(Obvious since DisplayMember is empty)
This only happens with the last item
What am I doing wrong?
This is the right way to change a ListBox DataSource (and it´s legal to do
it?)
Thanks
Marcos