ArrayList and ListBox

  • Thread starter Thread starter Bill Gower
  • Start date Start date
An ArrayList is not a 1 dimensional Array object (or
ListBoxObjectCOllection) which is what ListBox.AddRange accepts. You
can however pass ArrayList.ToArray.

listBox1.AddRange(arrayList1.ToArray(typeof());
or
listBox1.AddRange(arrayList1.ToArray(typeof(MyObject));

======================
Clay Burch
Syncfusion, Inc.
 
When I try the first one I get an error that say that it expects a type so I
put string[] as the parameter to typeof() and then I get an error stating
the AddRange method has some invalid arguments and it can't convert from
System.Array to System.Windows.Forms.ListBox.ObjectCollection.

Bill
 
I got it. It is listbox1.AddRange(ArrayList1.ToArray());

Bill Gower said:
When I try the first one I get an error that say that it expects a type so
I put string[] as the parameter to typeof() and then I get an error
stating the AddRange method has some invalid arguments and it can't
convert from System.Array to
System.Windows.Forms.ListBox.ObjectCollection.

Bill

ClayB said:
An ArrayList is not a 1 dimensional Array object (or
ListBoxObjectCOllection) which is what ListBox.AddRange accepts. You
can however pass ArrayList.ToArray.

listBox1.AddRange(arrayList1.ToArray(typeof());
or
listBox1.AddRange(arrayList1.ToArray(typeof(MyObject));

======================
Clay Burch
Syncfusion, Inc.
 
Back
Top