LstBox DisplayMember Problem

  • Thread starter Thread starter Marcos Ribeiro
  • Start date Start date
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
 
Hello,

Marcos Ribeiro said:
I Have a ListBox that uses an ArrayList with objects as
DataSource
[...]

Maybe somebody in this ng can help you:

news://news.microsoft.com/microsoft.public.dotnet.framework.windowsforms.databinding

HTH,
Herfried K. Wagner
 
Back
Top