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))))
Re: Selecting a Random items from a listbox and removing it.
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.
Re: Selecting a Random items from a listbox and removing it.
Quote:
Originally Posted by
dbasnett
What?
I would like it after it selects that random string. It will them remove itself from the listbox.
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.
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.
Re: Selecting a Random items from a listbox and removing it.
Quote:
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