【发布时间】:2020-01-31 20:39:41
【问题描述】:
我有一个 ComboBox 正在填充,其中 ComboBox.Items 中的每个对象都是一个对象列表。目前,组合框为每个项目显示“(集合)”。
是否可以让 ComboBox 显示 List 中包含 ComboBox 项目的第一个对象的成员?
我目前正在通过以下方式填充 ComboBox 项:
foreach(List<SorterIdentifier> sorterGroup in m_AvailableSorterGroups)
{
// There are conditions that may result in the sorterGroup not being added
comboBoxSorterSelect.Items.Add(sorterGroup);
}
//comboBoxSorterSelect.DataSource = m_AvailableSorterGroups; // Not desired due to the comment above.
//comboBoxSorterSelect.DisplayMember = "Count"; //Displays the Count of each list.
我希望在 ComboBox 中显示的值可以通过以下方式引用:
((List<SorterIdentifier>)comboBoxSorterSelect.Items[0])[0].ToString();
((List<SorterIdentifier>)comboBoxSorterSelect.Items[0])[0].DisplayName; // public member
【问题讨论】: