[RESOLVED] adding item from one listbox to another
hello there,
i'm trying to add items from one listbox to another by either a double click event or through a command button. i have been trying it out but haven't been able to get it.
heres a screen capture for clearer explanation.
http://i13.photobucket.com/albums/a2...listtolist.jpg
i have an inveterate impression towards List2.additem = itemsselected.List1.
i am also aware that the syntax is totally out of line, pardon me... im really new at this.
Thank You
Astro
Re: adding item from one listbox to another
How are you filling the liistboxes?
Is this in Access or VB?
If it is from an array or table, you just need a selected flag, that indicates that the item displayed is selected.
You can use the multi select option on the lisbox to give multiple selections, looping through the listbox entries or through the selected collections.
Re: adding item from one listbox to another
Hey Ecniv,
This is in VB.
The contents are from a table and i am afraid that i am not understanding what you're suggesting most definitely due to my inferior knowledge on vb.
Thank You
Astro
Re: adding item from one listbox to another
Example:
Code:
Table:
ID field1 flag
1 This false
2 Is false
3 The false
\/
List box (left displays all)
the you set the flags to true and the right list box displayas them.
The first column width must be 0 (so it is hidden) and holds the ID for the record.
The code under the button updates the flag field to false or true depending which way you want the record value to move.
(You can use an Update sql statement and execute it - works with IN or EXISTS with a multi select listbox.)
Re: adding item from one listbox to another
Is this what you mean?
VB Code:
Private Sub List1_DblClick()
'add to second list box
List2.AddItem List1.List(List1.ListIndex)
'remove from first listbox
List1.RemoveItem List1.ListIndex
End Sub
Re: adding item from one listbox to another
Quote:
Originally Posted by Hack
Is this what you mean?
VB Code:
Private Sub List1_DblClick()
'add to second list box
List2.AddItem List1.List(List1.ListIndex)
'remove from first listbox
List1.RemoveItem List1.ListIndex
End Sub
Hey Hack, i think you got it... i tried to add the codes it, but it doesn't seem to work. i'm playing around with it. Any ideas?
Thanks
Astro
Re: adding item from one listbox to another
Hello there, thanks for all the replies... unfortunately i still have problem resolving this. does anyone know how to allow an empty listbox to additem by double click on the items of another list box?
Astro
Re: adding item from one listbox to another
Hi,
Call you code like this
Private Sub List1_change()
List1_DblClick
end sub
It should work ??
Re: adding item from one listbox to another
Private Sub List1_DblClick(Cancel As Integer)
Me.List2.AddItem (List1.ListIndex) 'displays list of item
Me.List2.AddItem (List1.ItemData(0)) 'displays item with reference to index
End Sub
So far i can only add either the index itself or the data with reference to a fixed index to the next list.
Do i need some kinda loop here? How am i suppose to go about looping it?
Thank You
Astro
Re: adding item from one listbox to another
How many columns in the listbox?
1 Attachment(s)
Re: adding item from one listbox to another
In excel - but should be practically the same...
Re: adding item from one listbox to another
Hey Ecniv,
Got it! Thanks =)
Astro