开发者

Display the selected items (combobox) other values from a list<>

开发者 https://www.devze.com 2023-03-26 03:13 出处:网络
I have a comboBox filed from a list thus: locationCcomboBox.DataSource = ReadExcelFile(ExcelFilePath, "some properties"); \\\\ returns a list of class property.

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
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消