Odd behavior selecting from bound listbox

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?
 
E

Earl

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!
 

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