|
-
Apr 20th, 2013, 03:08 PM
#1
Thread Starter
Addicted Member
Selecting a Random items from a listbox and removing it.
What do I add to this when that random selection goes into lstBlue. I want it removed after it was added to lstBlue.
I got the selecting random to work so far.
Code:
Dim selectRnd As New Random
lstBlue.Items.Add(lstAll.GetItemText(lstAll.Items(selectRnd.Next(0, lstAll.Items.Count))))
-
Apr 20th, 2013, 06:28 PM
#2
Re: Selecting a Random items from a listbox and removing it.
-
Apr 20th, 2013, 06:29 PM
#3
Re: Selecting a Random items from a listbox and removing it.
You'll need to separate the random number selection to assign it it to a variable which you can use in both the add to lstBlue and remove from lstBlue commands.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Apr 20th, 2013, 07:19 PM
#4
Thread Starter
Addicted Member
Re: Selecting a Random items from a listbox and removing it.
 Originally Posted by dbasnett
What?
I would like it after it selects that random string. It will them remove itself from the listbox.
-
Apr 20th, 2013, 07:21 PM
#5
Thread Starter
Addicted Member
Re: Selecting a Random items from a listbox and removing it.
Could you give me a example. All I need it to do is when the random string is selected from the listbox it will appear the lstBlue and then remove itself from the original listbox it was taken from so I don't get repeats.
-
Apr 20th, 2013, 11:36 PM
#6
Re: Selecting a Random items from a listbox and removing it.
As has been said, don't put all your code into that one line. Generate a random number and assign it to a variable. That's one line. You can then use the number multiple times if you want. You can use it to index the Items collection of the first ListBox to get that item, which you can then add to the second ListBox. Finally, you have the original item and its index, so you can use Remove or RemoveAt to remove it from the first ListBox.
-
Apr 21st, 2013, 10:15 AM
#7
Thread Starter
Addicted Member
Re: Selecting a Random items from a listbox and removing it.
 Originally Posted by jmcilhinney
As has been said, don't put all your code into that one line. Generate a random number and assign it to a variable. That's one line. You can then use the number multiple times if you want. You can use it to index the Items collection of the first ListBox to get that item, which you can then add to the second ListBox. Finally, you have the original item and its index, so you can use Remove or RemoveAt to remove it from the first ListBox.
Thank you for your help! I will test this out
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
|