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

Re: (newbie) Slow Combobox Binding by Marco

Marco
Wed May 18 23:00:02 CDT 2005

the same hapens to me.. I still dont't know why, but the only workaround
I found is to set the DataSource or the DataMember again and refresh it

example:

myCombo.DataSource = myArrayList;
myCombo.DisplayMember = "Name";
myCombo.ValueMember = "ID";
myCombo.Refresh();

myCombo.DisplayMember = "Name";
myCombo.Refresh();

Marco

Jo Inferis escribió:
> 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
>
>

Re: (newbie) Slow Combobox Binding by Jo

Jo
Thu May 19 06:43:31 CDT 2005

Jo Inferis wrote:
> (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)

Oh. My. God.

Actually, the class definition was *more* dumb than that, and on reflection,
I'm wondering why the databinding worked *at all*. I had an accessor method
which attempted to return....the accessor method! GAH!

I have a feeling the ComboBox was internally having a fit but just not
telling me and eventually giving up and using the ToString() method on each
object rather than the broken ValueMember and DisplayMember properties it
was given...

I'll just go away and hide in a corner now :D

--
jo inferis



Re: (newbie) Slow Combobox Binding by ray

ray
Tue May 24 09:35:07 CDT 2005

Try this:

private string _Name;
public string Name
{
get
{
return _Name;
}
set
{
_Name =3D value;
}
}

The reason seems to be that ValueMember and DisplayMember only can be
used with Properties, they can=B4t be used with public variables. Don=B4t
know if it is a bug or not (I have no relationship with MS apart from
using .NET daily).

Jo Inferis wrote:
> Jo Inferis wrote:
> > (very basically, their class definition is just :
> > public class myClass
> > {
> > myClass() {}
> > myClass(int ID, string Name) { this.Name =3D Name; this.ID =3D ID;
}
> > public string Name;
> > public int ID;
> > }
> > - it's not quite that dumb, but you get the idea)
>
> Oh. My. God.
>
> Actually, the class definition was *more* dumb than that, and on
reflection,
> I'm wondering why the databinding worked *at all*. I had an accessor
method
> which attempted to return....the accessor method! GAH!
>
> I have a feeling the ComboBox was internally having a fit but just
not
> telling me and eventually giving up and using the ToString() method
on each
> object rather than the broken ValueMember and DisplayMember
properties it
> was given...
>
> I'll just go away and hide in a corner now :D
>=20
> --
> jo inferis