[英]DataGridView bound to BindingList displays empty rows
此代碼使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”列創建一個數據表,則其內容將以正確的方式顯示。
您需要將MyClass
的公共字段更改為相應的屬性:
public class MyClass
{
public int MyProp1 { get; set; }
public int MyProp2 { get; set; }
public int MyProp3 { get; set; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.