|
-
Jun 10th, 2004, 05:02 PM
#1
Thread Starter
Addicted Member
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?
-
Jun 10th, 2004, 05:27 PM
#2
Sleep mode
VB Code:
ListBox2.SelectedIndex=ListBox2.Items.Count-1
-
Jun 10th, 2004, 05:32 PM
#3
Thread Starter
Addicted Member
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?
-
Jun 10th, 2004, 05:57 PM
#4
Sleep mode
Yes , I guess . I'm not at my dev computer right now so I'll try when I get home .
-
Jun 10th, 2004, 06:23 PM
#5
New Member
insert this line between ur intial two codes.
ListBox2.SelectedItem = ListBox1.SelectedItem
-
Jun 10th, 2004, 06:44 PM
#6
PowerPoster
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.
-
Jun 10th, 2004, 07:43 PM
#7
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|