Monday, July 29, 2013

C# Public Override Method

If you want the EEID property to be displayed in a ComboBox you can just use the DisplayMember property:



comboBox1.DataSource = new List<Person>(){ ... };
comboBox1.DisplayMember = "Id";
comboBox1.ValueMember = "Id";

If you want both the name and the id to show, you can add another property to the Customer class and set the DisplayMember property of the ComboBox to the name of this one:



public Customer
{
....
public string DisplayName
{
get { return String.Format("{0} {1}, ID: {2}", firstname, lastname, id); }
}
}


No comments:

Post a Comment