1

こんなクラスがありますが、

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;  
 }
}

私のウィンドウフォームでは、アイテムリストを取得し、それをデータグリッドビューのデータソースに割り当てています。

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 に追加したカスタム プロパティがグリッドに表示されません。これを克服するためにコードを変更するにはどうすればよいですか。

4

1 に答える 1

-1

これを試して

設定

bindingSource.DataMember = "Your value";  // 

http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.aspx

于 2013-10-11T05:21:36.213 に答える