我正在尝试将一个泛型列表(如List Parents)绑定到ComboBox上。
当我运行我的测试应用程序时,我只看到:“ComboBindingToListTest.Parent”在我的ComboBox中显示,而不是“SHOW THIS”。如何通过一级或更深的属性(例如child.DisplayMember)将ComboBox绑定到通用列表?
提前致谢, Adolfo
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”。如何通过一级或更深的属性(例如child.DisplayMember)将ComboBox绑定到通用列表?
提前致谢, Adolfo