I have a comboBox filed from a list thus:
locationCcomboBox.DataSource = ReadExcelFile(ExcelFilePath, "some properties"); \\ returns a list of class property.
locationCcomboBox.DisplayMember = "Location开发者_Go百科";
the Class is a simple class:
public string chain { get; set; }
public string location { get; set; }
public string postcode { get; set; }
public string phone { get; set; }
What I can't get into my head is how when the user selects an option from the combobox is how I select the phone,chain etc to write the correct value out to a text box for each!
BrainGoneSouth!
Handle the SelectedIndexChanged
event of your locationCcomboBox
an then get your class instance by the SelectedItem
property:
//At form load or constructor:
locationCcomboBox.SelectedIndexChanged += locationCcomboBox_SelectedIndexChanged;
private void locationCcomboBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (locationCcomboBox.SelectedIndex > -1)
{
Class myClass = locationCcombo.SelectedItem as Class;
if (myClass != null)
{
//access the members of myClass here
}
}
}
精彩评论