How to populate a combobox with an ArrayList containing 1 dimensional array of strings?

P

polaris431

All the examples I've seen showing how to populate a combobox using the
DataSource property and an ArrayList show the ArrayList object
containing objects with at least two properties. I want to create an
ArrayList that contains only rows of string data and want to assign
this to the DataSource but I can't figure out what to set the
ValueMember or DisplayMember to. Example

ArrayList myData = new ArrayList();

myData.Add("abc");
myData.Add("def");

ComboBox combo = new ComboBox();
combo.DataSource = myData;
combo.ValueMember = ???
combo.DisplayMember = ???
 
S

Stoitcho Goutsev \(100\)

Hi,

Don't set anything. If this properties are not set the combobox will use the
object itself as display and value member. You need this properties only if
you set up the combobox with collection of complex objects - that have
properties on their own and you one use them to provide the visual and the
value.
 
B

Bry

All the examples I've seen showing how to populate a combobox using the
DataSource property and an ArrayList show the ArrayList object
containing objects with at least two properties. I want to create an
ArrayList that contains only rows of string data and want to assign
this to the DataSource but I can't figure out what to set the
ValueMember or DisplayMember to. Example

ArrayList myData = new ArrayList();

myData.Add("abc");
myData.Add("def");

ComboBox combo = new ComboBox();
combo.DataSource = myData;
combo.ValueMember = ???
combo.DisplayMember = ???

Do you need to use a DataSource?

Why not just use the following:

ArrayList myData = new ArrayList();
myData.Add("abc");
myData.Add("def");

foreach (string s in myData)
combo.Items.Add(s);

Bry
 
P

polaris431

I want to avoid using a loop.

Why not just use the following:

ArrayList myData = new ArrayList();
myData.Add("abc");
myData.Add("def");

foreach (string s in myData)
combo.Items.Add(s);

Bry- Hide quoted text -- Show quoted text -
 

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