更新时间:2021-11-12 03:02:52
列表不落实 IBindingList的
所以网格不知道你的新项目。
List does not implement IBindingList
so the grid does not know about your new items.
绑定你的DataGridView到的BindingList< T>
而不是
Bind your DataGridView to a BindingList<T>
instead.
var list = new BindingList<Person>(persons);
myGrid.DataSource = list;
不过,我甚至会更进一步,网格绑定到的BindingSource
var list = new List<Person>()
{
new Person { Name = "Joe", },
new Person { Name = "Misha", },
};
var bindingList = new BindingList<Person>(list);
var source = new BindingSource(bindingList, null);
grid.DataSource = source;