【发布时间】:2011-08-06 12:35:57
【问题描述】:
我正在尝试将像 List parents 这样的通用列表绑定到 ComboBox。
public Form1()
{
InitializeComponent();
List<Parent> parents = new List<Parent>();
Parent p = new Parent();
p.child = new Child();
p.child.DisplayMember="SHOW THIS";
p.child.ValueMember = 666;
parents.Add(p);
comboBox1.DisplayMember = "child.DisplayMember";
comboBox1.ValueMember = "child.ValueMember";
comboBox1.DataSource = parents;
}
}
public class Parent
{
public Child child { get; set; }
}
public class Child
{
public string DisplayMember { get; set; }
public int ValueMember { get; set; }
}
当我运行我的测试应用程序时,我只看到:“ComboBindingToListTest.Parent”显示在我的 ComboBox 中,而不是“SHOW THIS”。 如何通过一级或更深的属性将 ComboBox 绑定到通用列表,例如child.DisplayMember??
提前致谢, 阿道夫
【问题讨论】:
标签: c# winforms binding combobox generic-list