getting listbox selections

spinkung

Registered User.
Local time
Today, 12:57
Joined
Dec 4, 2006
Messages
267
Hi all,

I have a listbox on a form which i want to be able to make multiple selections from and pass into another listbox.

how do i put the selected items into the other box?

is there a way of telling if something is selected in a list box (by the index or something)? If so then i shuld be able to loop throung the selected items but how to i append them to my second listbox?

sorry if this is a bit noobish but ....well....im a noob.

Thanks, Spinkung
 
I think this is considered cascading list boxes. Try doing a search on the forum and see if you get what you need - :)
 
Hi, thanks for your reply. I have looked at cascading listboxes but dont think its what im after. I dont want the second list box to have values based on what is selected in the first. I want to actually copy the values i have selected in list1 into list2.

basically, list1 one shows ,say, 10 stockcodes and there serial numbers. i want to be able to select 5 of those items and transfer them into list2.

Is this cascading??
 
Not technically, but you should be able to one and use a similar set up to get what you need...
 
Sorry - My browser won't allow me to edit my post, I left out a significant word in my last post:

Not technically, but you should be able to disect one and use a similar set up to get what you need...
 
thanks for your help. I managed to crack it with your advise. I just have one more thing (**i hear you sigh**).

I now have my items in my second listbox. I want to get those values (serial no's) and update a table with the items in the list. How do i go about getting the number of items that are actually in the list box so i can use the number in a loop?

Many Thanks.
 
I think he means selected items in the list, which is the ItemSelected property. Use listcount -1 (because a listbox index starts at zero) and loop through the listbox, as in it ListIndex(X) = listbox.ItemSelected = True? Change the X to listcount (for/next loop) and you can figure out what is selected and what is not.
 
Thanks for your replies.

I have another issue though.....

I'm using this code to move my selected items to my second list box.

Code:
Dim ctl As Control
Dim varItm As Variant, intI As Integer
Dim i1 As String

Set ctl = Me.listBox1
For Each varItm In ctl.ItemsSelected
    For intI = 0 To ctl.ColumnCount - 1
        i1 = ctl.Column(intI, varItm)
        Me.listBox2.AddItem (i1)
    Next intI
    'Debug.Print
Next varItm

but instead of copying the columns like this.....

Listbox1
Col1.......Col2........Col3

Listbox2
Col1.......Col2........Col3


Whats actually happening is.....


Listbox1
Col1.......Col2........Col3

Listbox2
Col1
Col2
Col3

Can anyone help??
Thanks.
 

Users who are viewing this thread

Back
Top Bottom