vb.net - populate one listbox from another

L

lolly

Hi all just wondering if any one has any idea on the following...

I have two listboxes -

one listbox populated from a database
ListBox1.Items.Add(dr("NAME"))
and the user can collect multiple items.

The next listbox is populated from the selected items from Listbox1.

I'm having trouble populating the Listbox2. Setting the datasource to
Listbox1.SelectedItems works but I want the user to have an option to
clear the Listbox2 -
ListBox1.ClearSelected()
ListBox2.Items.Clear()

But you cannot use this when the Datasource is set.

I have tried this: ListBox2.Items.Add(ListBox1.SelectedItems)

But it doesnt work!!

Thanks!!
 
R

RobinS

Try cycling through them and adding them.

For i As Integer = 0 to ListBox1.SelectedIndeces.Count - 1
ListBox2.Items.Add(FieldListBox.SelectedIndeces(i))
Next i

Robin S.
 

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