Home All Groups Group Topic Archive Search About

listboxes to select/deselect multiple items

Author
24 Mar 2005 2:47 PM
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

Author
24 Mar 2005 4:47 PM
Terry Burns
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






Show quoteHide quote
"Bill Nguyen" <billn_nospam_please@jaco.com> wrote in message
news:%23MeB0BIMFHA.568@TK2MSFTNGP09.phx.gbl...
>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
>
Author
6 Apr 2005 9:04 PM
Bill Nguyen
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

Show quoteHide quote
"Terry Burns" <u*@ourWebSite.com> wrote in message
news:%23%23ZA1EJMFHA.3420@tk2msftngp13.phx.gbl...
> 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
>
>
>
>
>
>
> "Bill Nguyen" <billn_nospam_please@jaco.com> wrote in message
> news:%23MeB0BIMFHA.568@TK2MSFTNGP09.phx.gbl...
>>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
>>
>
>