listboxes to select/deselect multiple items

  • Thread starter Thread starter Bill Nguyen
  • Start date Start date
B

Bill Nguyen

I would like to be able to do the following:

Listbox1/Textbox1 contains list of all items not selected

item A
item B
item D

Listbox2//Textbox2 contains list of all items selected

item C
item E

User then can highlight desired items to select/deselect using the
corresponding arrows (or the like).

Any sample/tip is greatly appreciated.

Bill
 
There are usually several ways, here is one which uses the
SelectedIndexChamnged Event of the source Listbox. In my Example, I have
named them lb1 and lb2 ( source and destination respectively )

Private Sub lb1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles lb1.SelectedIndexChanged

Dim o As Object

Dim senderBox As ListBox

senderBox = DirectCast(sender, ListBox)

lb2.Items.Clear()

For Each o In senderBox.SelectedItems

lb2.Items.Add(o)

Next

End Sub

-
Terry Burns
http://TrainingOn.net
 
Thanks Terry;
I'll try this.
Bill

Terry Burns said:
There are usually several ways, here is one which uses the
SelectedIndexChamnged Event of the source Listbox. In my Example, I have
named them lb1 and lb2 ( source and destination respectively )

Private Sub lb1_SelectedIndexChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles lb1.SelectedIndexChanged

Dim o As Object

Dim senderBox As ListBox

senderBox = DirectCast(sender, ListBox)

lb2.Items.Clear()

For Each o In senderBox.SelectedItems

lb2.Items.Add(o)

Next

End Sub

-
Terry Burns
http://TrainingOn.net
 
Terry;
I would like to remove the selected items from senderBox once they moved to
lb2 in your example. I can seem to make it work I tried to use
..Items.Remove(.selectedindex) but the items remain in the senderBox.

Please help!

Thanks
Bill
 

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