Populate Combo/List Box with ArrayList

G

Greg

Can someone give me e simple example of to populate a combo box / list box
using an ArrayList?

THanks.
 
C

Cor Ligthert[MVP]

Greg,

You should not want to do that, however if it is what you want, than you
only have to populate the itemlist of the combobox for that however than you
can only use the selected text to get the values.

You can as well use a way with objects in a list, but then you should cast
the returned objects from datarowviews, a little bit more work than when you
use a bindingsource with a more modern collection.

Cor
 
T

Tom Shelton

Can someone give me e simple example of to populate a combo box / list box
using an ArrayList?

THanks.

Yikes! An arraylist... If your using VB2005 or latter, consider
using a List(Of T). It will give you type safty and better
performance then an arraylist. If you need to store objects of
different types, then I usually would use List(Of Object) over an
arraylist...

Anyway, to add the items in an arraylist to a listbox/combobox....

ListBox1.Items.AddRange (myArrayList.ToArray())
 
L

Lloyd Sheen

Greg said:
Can someone give me e simple example of to populate a combo box / list box
using an ArrayList?

THanks.

Dim myArrayList As New ArrayList

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
For i As Integer = 0 To 9
myArrayList.Add(i.ToString)
Next
ListBox1.DataSource = myArrayList
End Sub

It can be done but I agree with Tom that using an arraylist is not the best
way to go if you are using VS 2005 or up.

Lloyd Sheen
 
G

Greg

I have never used an array list to populate either as of yet. I generally use
DataSets or DataTables instead. I was just curious as too whether this could
be done or not.

Thanks for your opinions and assistance everyone.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top