Could someone please explain

  • Thread starter Thread starter Beringer
  • Start date Start date
B

Beringer

I'm trying to set a datasource of a combobox to an ArrayList and want to set
the DisplayMember and ValueMember properties of the combobox to items in the
ArrayList.

I reviewed the example with US States found in VS but don't understand how
setting the DisplayMember and ValueMember properties works.
The member properties are to be set to string values of the names of the
properties to use in the DataSource. This doesn't make sense to me. What
are the properties of an ArrayList that can be used?

Thank you in advance,
Eric
 
Hi,
DisplayMember displays the the list of values for the list control, whereas
ValueMember is the value the control hold for account for that DisplayMember
when you select or change the display. e.g.

EmpId EmpName
101 Roger
102 John
103 Micheal

Here, you set the DisplayMember & ValueMember as EmpName and EmpId resp.
Now, when you select or change the EmpName, the corrosponding EmpId is
picked up for calculation. Is that clear ?

Regards
Joyjit
 
I understand the properties but don't understand where "EmpID" and "EmpName"
come from.
What are these names of? What kind of object do they belong too?
ArrayList, Class etc.

See I assume you set the DataSource to an object like an arraylist. Using
your example:

struct Employee
{
int EmpId;
string EmpName;
....other code for structure
}

ArrayList Employees;
(add empolyees to the list)

ListControl.DataSource = Employees;
ListControl.DisplayMember = "EmpName";
ListControl.DisplayValue = "EmpId";

blah, blah, blah....

The above will throw an exception, saying something like "Can't Set
DisplayMember".

Thanks again,
Eric
 
Back
Top