Odd behavior selecting from bound listbox

  • Thread starter Thread starter Earl
  • Start date Start date
E

Earl

I have a listbox that I bind to an arraylist like so:

'in the module
Public CustomerList As New ArrayList

Public Sub PopulateCustomers()
'..... using DataReader
End Sub

'in the form class
lstCustomers.DisplayMember = ToString()
lstCustomers.ValueMember = "CustomerID"
lstCustomers.DataSource = CustomerList

Now if I unbind the datasource, I can read a SelectedValue of 0, but if I do
not unbind the datasource, the SelectedValue property returns the TEXT value
of the DisplayMember instead of the Int32 value of CustomerID and I
obviously get an error. Anyone seen this?
 
Aaaaaaaaaaargh ... found it ... had used the plural form for my
Customer(s)ID in populating the arraylist (have the Customer class with a
singular property name). Somewhat obscure error because the arraylist didn't
return an error nor did the Customer listbox -- even with the ValueMember
set to a non-existent class property!
 
Back
Top