泛型绑定的一个问题
绑定的语句是:
List<TUnitObject> units = TUnitFacade.GetData();
cBUnit.DataSource = units;
cBUnit.DisplayMember = "Unit_Name";
cBUnit.ValueMember = "Unit_Id";
当TUnitObject是这样的时候发现是绑定不上去的
public struct TUnitObject
{
public string Unit_Id;
public string Unit_Name;
public TUnitObject(string unit_Id, string unit_Name)
{
Unit_Id = unit_Id;
Unit_Name= unit_Name;
}
}
后来修改了一下,就可以了:
public struct TUnitObject
{
private String fId;
private String fName;
public string Unit_Id
{
get { return fId; }
}
public string Unit_Name
{
get { return fName; }
}
public TUnitObject(string unit_Id, string unit_Name)
{
fId = unit_Id;
fName = unit_Name;
}
}
结论是“绑定DataSource只能用属性,貌似”