Advertisement
BaSs_HaXoR

Get Random listBox Item to String C#

Oct 19th, 2014
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.46 KB | None | 0 0
  1. Random random = new Random();
  2.             int randomNumber = random.Next(1, listBox1.Items.Count);
  3.             listBox1.Select();
  4.             listBox1.SelectedItem = listBox1.Items[randomNumber];
  5.             var str = listBox1.SelectedItem;
  6.           // MessageBox.Show(str.ToString());
  7.      //or
  8.     string bass = str.ToString();
  9. //SOURCE: https://stackoverflow.com/questions/11771050/how-do-i-get-a-random-item-from-a-listbox-then-compare-it-in-c
  10. //Answered by Habib
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement