ItHelp

ItHelp

  • NA
  • 2
  • 0

How to Randomize the Contents of a combobox when the Form is Loaded?

Apr 3 2009 9:51 AM

I have an string array that populates a combobox, I need for the combobox to change the order each time the program is loaded.

I Have code that does this but it only provides for me the index numbers, but not the string value of the array:

Random random = new Random();

foreach (string s in stringArray)
                {
                    combobox1.Items.Add(random.Next(stringArray.Length));
                }

I need every Value in the array to appear once just like the array but in different order.

I have tried to write code that gives me text: but it repeats some string values and the items in the combobox are not equal to stringArray.Length:

foreach (string s in stringArray)
                {
                  if (combobox1.Items.Contains(s))
                            {
                                 combobox1.Items.Add(stringArray.GetValue(random.Next(stringArray.Length)));
                            }
                 }




Thanks


Answers (1)