1

此代码导致DataGridView grid显示空行,尽管它有一列DataPropertyName设置为“MyProp1”:

public class MyClass
{
  public int MyProp1;
  public int MyProp2;
  public int MyProp3;
}

public class MyItems:IListSource
{
  BindingList<MyClass> _items = new BindingList<MyClass>();

  //..............................

  //IListSource
  public bool ContainsListCollection
  {
      get { return false; }
  }

  //IListSource
  public System.Collections.IList GetList()
  {
      return _items;
  }
}

MyItems i = new MyItems();
.............
//MyItems list is populated
.............
grid.DataSource = i;

有什么问题?

如果我用“MyProp1”列创建一个 DataTable,它的内容就会以正确的方式显示。

4

1 回答 1

8

您需要将公共字段更改MyClass为相应的属性:

public class MyClass
{
   public int MyProp1 { get; set; }
   public int MyProp2 { get; set; }
   public int MyProp3 { get; set; }
}
于 2013-10-22T18:20:53.197 回答