我有这样的课,
public class Item
{
private string _itemCode=string.empty;
private string _itemName = string.empty;
//Dynamic variable to keep custom properties
private dynamic _customProperties = new ExpandoObject();
public string ItemCode
{
get{return _itemCode;}
set{_itemCode=value;}
}
public string ItemName
{
get{return _itemName;}
set{_itemName=value;}
}
private ExpandoObject CustomProperties
{ get { return _customProperties; } }
//Method to load objects
publc static List<Item> Load()
{
List<Item> itemList = new List<Item>();
//Create Item objects
Item itm1 = new Item();
{
_itemCode="Code1";
_itemName="Name1";
}
//Create custom properties
itm1._customProperties.Test1 = "t1";
itemList.Add(itm1);
//Add more items as above with the several custom properties
return itemList;
}
}
在我的 Windows 窗体中,我得到一个项目列表并将其分配给 datagridview 的数据源。
List<Item> lstItems= Item.Load();
//Add item list to the data grid view
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = lstItems;
this.dataGridView1.DataSource = bindingSource;
this.dataGridView1.Refresh();
当表单运行时,网格不显示我添加到 Item.CustomProperties 的自定义属性。我怎样才能改变我的代码来克服这个问题。