VB.Net - choosing a random item from a combobox?
Hi, i have a combobox with few items in it...
Example:
Apple, Orange, Lemon
How do i code it when Apple is chosen then It will randomly pick between the other options in the combobox besides what you chose so orange or lemon and set it as the randomfruit label?
Its an easy question, i just don't know the answer.
Thanks in advance,
Update:I tried Rachet, also tried changing the random to loop until the selected item = false but both times my program goes non responsive once i select an item in the combobox
Comments
Something like this should work:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim r As New Random
Dim g As Integer
Do
g = r.Next(ComboBox1.Items.Count)
Loop While g = ComboBox1.SelectedIndex
TextBox1.Text = ComboBox1.Items(g).ToString()
End Sub