471,317 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

load arrayList into ListBox.ObjectCollection

This is wrong but it seems I might be on track somewhat close:
I want to display my ArrayList of Random numbers in the list box.
Below you see this as aLRandoms.

There seems to be a provision to load a range :
listBox1.Items.AddRange(lboxObjCol);

so I try to load the lboxObjCol as shown:
System.Windows.Forms.ListBox.ObjectCollection lboxObjCol = new
ListBox.ObjectCollection(listBox1, (object)aLRandoms);
where the 2nd param is Object [] value ...

thanks
--
Andrew
Feb 15 '06 #1
2 15429
Here's the answer after some digging: ( answer by self )

int intMaxElements = aLRandoms.Count; // where aLRandoms is an ArrayList
object[] bunchOfStuff = new object[intMaxElements];
System.Windows.Forms.ListBox.ObjectCollection lboxObjCol = new
ListBox.ObjectCollection(listBox1, bunchOfStuff);
listBox1.Items.AddRange(lboxObjCol);

Works perfectly.....
--
Andrew
"andrewcw" wrote:
This is wrong but it seems I might be on track somewhat close:
I want to display my ArrayList of Random numbers in the list box.
Below you see this as aLRandoms.

There seems to be a provision to load a range :
listBox1.Items.AddRange(lboxObjCol);

so I try to load the lboxObjCol as shown:
System.Windows.Forms.ListBox.ObjectCollection lboxObjCol = new
ListBox.ObjectCollection(listBox1, (object)aLRandoms);
where the 2nd param is Object [] value ...

thanks
--
Andrew

Feb 15 '06 #2
// forgot to add : cRandoms.CopyTo(bunchOfStuff);

int intMaxElements = cRandoms.Count;
object[] bunchOfStuff = new object[intMaxElements];
cRandoms.CopyTo(bunchOfStuff);
System.Windows.Forms.ListBox.ObjectCollection lboxObjCol = new
ListBox.ObjectCollection(listBox1, bunchOfStuff);
listBox1.Items.AddRange(lboxObjCol);
--
Andrew
"andrewcw" wrote:
Here's the answer after some digging: ( answer by self )

int intMaxElements = aLRandoms.Count; // where aLRandoms is an ArrayList
object[] bunchOfStuff = new object[intMaxElements];
System.Windows.Forms.ListBox.ObjectCollection lboxObjCol = new
ListBox.ObjectCollection(listBox1, bunchOfStuff);
listBox1.Items.AddRange(lboxObjCol);

Works perfectly.....
--
Andrew
"andrewcw" wrote:
This is wrong but it seems I might be on track somewhat close:
I want to display my ArrayList of Random numbers in the list box.
Below you see this as aLRandoms.

There seems to be a provision to load a range :
listBox1.Items.AddRange(lboxObjCol);

so I try to load the lboxObjCol as shown:
System.Windows.Forms.ListBox.ObjectCollection lboxObjCol = new
ListBox.ObjectCollection(listBox1, (object)aLRandoms);
where the 2nd param is Object [] value ...

thanks
--
Andrew

Feb 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by andrewcw | last post: by
5 posts views Thread by markr1000 | last post: by
4 posts views Thread by Anand Ganesh | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.