kimiraikkonen said:
Hi, that doesn't work, only works with listbox's multiselect
(multiselect at the same time) function which is offtopic. I want to 2
thins if anyone can help:
For random selection procedure(as Kerry and Family Tree Mike helped);
1- I want an listbox item selected only for once, i don't want a
listbox item selected for twice or three (random order).
2-When all the items are selected in a random order, i want to get a
msgbox("all items were selected, there is no item left unselected in
random order").
Thanks!
I think you want something like this. the list loi should be a form level
member while the rest is in a routine where you are changing the selected
item. Somehow, depending on your requirements, you will need to know that
the routine could not pick any more entries.
Here is the code:
Dim loi As New System.Collections.Generic.List(Of Integer)
public bool NextRandomClick()
Dim r As New Random
Dim idx As Integer
If (loi.Count = ListBox1.Items.Count) Then
MsgBox("All have been selected...")
Return false
End If
idx = r.Next(0, ListBox1.Items.Count)
While (loi.Contains(idx))
idx = r.Next(0, ListBox1.Items.Count)
End While
ListBox1.SelectedIndex = r.Next(0, ListBox1.Items.Count - 1)
return true
end function