I'm fairly new to winforms, but I've been playing around with ASP.NET for a
while, so I'm familiar with a fair bit of the framework, however I'm having
an annoying issue when trying to bind a simple arraylist to a combobox.
All I want the combobox to be is a simple dropdownlist and I'll grab the
SelectedValue from it to do other stuff elsewhere, so what I thought I could
do is :
myCombo.DataSource = myArrayList;
myCombo.DisplayMember = "Name";
myCombo.ValueMember = "ID";
Where myArrayList is an ArrayList (shock!) of simple objects with the
properties "Name"(string) and "ID"(int).
(very basically, their class definition is just :
public class myClass
{
myClass() {}
myClass(int ID, string Name) { this.Name = Name; this.ID = ID; }
public string Name;
public int ID;
}
- it's not quite that dumb, but you get the idea)
I'm finding that not only is DisplayMember *completely ignored* (i.e. all
the entries in the combobox merely display "myNamespace.myClass"), but the
binding process seems to take an inordinately long amount of time -
somewhere up to 5 seconds. I thought initially it was a database access time
or the size of the ArrayList slowing it down, but I actually reduced it to :
ArrayList myArrayList= new ArrayList();
myArrayList.Add(new myClass(1, "First"));
myArrayList.Add(new myClass(2, "Second"));
myCombo.DataSource = myArrayList;
myCombo.DisplayMember = "Name";
myCombo.ValueMember = "ID";
and it still takes seconds!
Can anyone shed any light on this?
thanks in advance,
--
jo inferis