Results 1 to 7 of 7

Thread: Easy (I Hope) Listbox Question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    154

    Easy (I Hope) Listbox Question

    I have 2 listboxes. When I select an item (single select) in listbox 1 and hit a button it moves the item from listbox1 to listbox 2, and also then deletes that item from listbox1. The part I'm having trouble with is trying to figure out how to make it so that after that code is executed, to select the newly added item in listbox 2 (using something like selectedindex I'm assuming). Thanks.

    Here's my code:

    ---------------------------------------------------------------
    ListBox2.Items.Add(Listbox1.SelectedItem)
    ListBox1.Items.Remove(ListBox1.SelectedItem)

    ---------------------------------------------------------------

    So now how do I make it so that the listbox2 item that was just added gets selected?

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. ListBox2.SelectedIndex=ListBox2.Items.Count-1

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    154
    oh shoot. I forgot to tell you that my listbox is sorted, so it wouldn't be at the end like your code looks for So is there a way for me to select the item that was just put in the listbox if it's a sorted listbox?

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Yes , I guess . I'm not at my dev computer right now so I'll try when I get home .

  5. #5
    New Member
    Join Date
    Aug 2003
    Posts
    15
    insert this line between ur intial two codes.

    ListBox2.SelectedItem = ListBox1.SelectedItem

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by ca1n3
    oh shoot. I forgot to tell you that my listbox is sorted, so it wouldn't be at the end like your code looks for So is there a way for me to select the item that was just put in the listbox if it's a sorted listbox?

    ListBox2.Items.Add(Listbox1.SelectedItem)
    Listbox2.SelectedItem=ListBox1.SelectedItem
    ListBox1.Items.Remove(ListBox1.SelectedItem)


    See, You knew it all the time
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    154
    Works like a charm, thanks guys

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