0

Hey,

I am working on this small project that will shuffle an array of names and then will load them into 5 list boxes. I have 25 names and need to load 5 names per listbox. Need some suggestions on how would i go about accomplishing someting like this. Thanks!

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by CloneXpert
0

Hi, I would use something like this, but I'm sure there are much better ways doing it.

string[] names = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i","j", "k" };
            int element = 0;
            List<ListBox> list = new List<ListBox>();
            list.Add(listBox1);
            list.Add(listBox2);
            list.Add(listBox3);
            list.Add(listBox4);
            list.Add(listBox5);
            while ( element < names.Length )
            {
                foreach ( ListBox lb in list )
                {
                    if ( element >= names.Length ) 
                        break;
                    lb.Items.Add(names[ element++ ].ToString());
                }
            }

Hope it helped :)

0

Thanks alot man, this helped alot. Now i have some extra time to tweak with the program.:)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.