|
-
June 23rd, 2009, 08:22 PM
#1
How do i output an array to a ListBox?
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.
-
June 23rd, 2009, 08:23 PM
#2
Re: How do i output an array to a ListBox?
So you want to add all of the items in a given array to a ListBox control I take it?
R.I.P. 3.5" Floppy Drives
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
-
June 23rd, 2009, 08:25 PM
#3
Re: How do i output an array to a ListBox?
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).
-
June 23rd, 2009, 08:27 PM
#4
Re: How do i output an array to a ListBox?
Your in luck Microsoft has a nice little function that you can do just that with:
Code:
myListBox.Items.AddRange(myArray);
There you go, thats it. Piece of cake 
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.
Last edited by RaleTheBlade; June 23rd, 2009 at 08:30 PM.
R.I.P. 3.5" Floppy Drives
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
-
June 23rd, 2009, 08:28 PM
#5
Re: How do i output an array to a ListBox?
Thank you very much, you rock 8).
-
June 23rd, 2009, 08:37 PM
#6
Re: How do i output an array to a ListBox?
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.
R.I.P. 3.5" Floppy Drives
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
-
June 23rd, 2009, 08:39 PM
#7
Re: How do i output an array to a ListBox?
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;.
-
June 23rd, 2009, 08:41 PM
#8
Re: How do i output an array to a ListBox?
Wow, I didnt even know you could do that. Awesome... we both learned something new today, lol.
R.I.P. 3.5" Floppy Drives
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
-
June 23rd, 2009, 08:43 PM
#9
Re: How do i output an array to a ListBox?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|