I apologize, i'm very new to C# and i can't find a resource to help me iterate and output an array to a Listbox in C#. Am i correct to assume that a Listbox is the correct control? Any help would be much appreciated.
Printable View
I apologize, i'm very new to C# and i can't find a resource to help me iterate and output an array to a Listbox in C#. Am i correct to assume that a Listbox is the correct control? Any help would be much appreciated.
So you want to add all of the items in a given array to a ListBox control I take it?
That is correct, i have my array created. Now i want to iterate through and output the array to a listbox ( or whatever control is more appropriate).
Your in luck :D Microsoft has a nice little function that you can do just that with:
There you go, thats it. Piece of cake :thumb:Code:myListBox.Items.AddRange(myArray);
EDIT: After playing with the function a little more... it seems as though doing AddRange() with an array of value types (int, double, long, etc...) throws an error. But that shouldnt be the case since every object in C#, including value types, inherit from System.Object and AddRange() expects an array of objects.
Thank you very much, you rock 8).
No problem, I edited my post though so you may want to check it out to get a heads up on any future endeavors like this.
Yes, i received an exception. But after searching with your input i was able to find another solution that worked fine for my code: myListBox.DataSource = myArray;.
Wow, I didnt even know you could do that. Awesome... we both learned something new today, lol.
Thx again.