显示所选项目(组合框)和列表中的其他值<>

本文关键字:列表 其他 选项 项目 组合 显示 | 更新日期: 2023-09-27 18:04:36

我有一个来自列表的comboBox文件:

locationCcomboBox.DataSource = ReadExcelFile(ExcelFilePath, "some properties"); '' returns a list of class property.
locationCcomboBox.DisplayMember = "Location";

类是一个简单类:

public string chain { get; set; }
public string location { get; set; }
public string postcode { get; set; }
public string phone { get; set; }

我不能进入我的头是如何当用户选择一个选项从组合框是我如何选择电话,链等写入正确的值为每个文本框!

<标题> BrainGoneSouth !

显示所选项目(组合框)和列表中的其他值<>

处理locationCcomboBoxSelectedIndexChanged事件,然后通过SelectedItem属性获得您的类实例:

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