Listbox.SelectedObjectCollection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've added objects to a listbox using

lst.DisplayMember = "CustomerName"
lst.Items.Add(New CCustomer( theData("ID"), theData("CustomerName")))

if I used lst.SelectedIndex I always get the last item in the list irrespective of whether it was selected. So I thought perhaps I should be using the SelectedObjectCollection.

I can't figure out how to use it, can someone show me some example code

I was thinking

for each obj in lst.SelectedObjectCollection

but the compiler doesnt like this it says
"SelectedObjectCollection is a type and cannot be used in an expression"

Thanks
 
Hi,

Use SelectedItems instead.

Ken
-------------------
I've added objects to a listbox using

lst.DisplayMember = "CustomerName"
lst.Items.Add(New CCustomer( theData("ID"), theData("CustomerName")))

if I used lst.SelectedIndex I always get the last item in the list
irrespective of whether it was selected. So I thought perhaps I should be
using the SelectedObjectCollection.

I can't figure out how to use it, can someone show me some example code

I was thinking

for each obj in lst.SelectedObjectCollection

but the compiler doesnt like this it says
"SelectedObjectCollection is a type and cannot be used in an expression"

Thanks
 

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

Back
Top