Results 1 to 12 of 12

Thread: [RESOLVED] adding item from one listbox to another

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    90

    Resolved [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

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    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.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    90

    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

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    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.)

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: adding item from one listbox to another

    Is this what you mean?
    VB Code:
    1. Private Sub List1_DblClick()
    2. 'add to second list box
    3. List2.AddItem List1.List(List1.ListIndex)
    4. 'remove from first listbox
    5. List1.RemoveItem List1.ListIndex
    6. End Sub

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    90

    Re: adding item from one listbox to another

    Quote Originally Posted by Hack
    Is this what you mean?
    VB Code:
    1. Private Sub List1_DblClick()
    2. 'add to second list box
    3. List2.AddItem List1.List(List1.ListIndex)
    4. 'remove from first listbox
    5. List1.RemoveItem List1.ListIndex
    6. 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

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    90

    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

  8. #8
    Junior Member
    Join Date
    Aug 2005
    Posts
    24

    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 ??

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    90

    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

  10. #10
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: adding item from one listbox to another

    How many columns in the listbox?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  11. #11
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: adding item from one listbox to another

    In excel - but should be practically the same...
    Attached Files Attached Files

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jun 2005
    Posts
    90

    Re: adding item from one listbox to another

    Hey Ecniv,

    Got it! Thanks =)

    Astro

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width