更新时间:2022-03-22 03:00:55
List 没有实现 IBindingList
所以网格不知道你的新项目.
List does not implement IBindingList
so the grid does not know about your new items.
将您的 DataGridView 绑定到 BindingList
.
Bind your DataGridView to a BindingList<T>
instead.
var list = new BindingList<Person>(persons);
myGrid.DataSource = list;
但我什至会更进一步,将您的网格绑定到 BindingSource
But I would even go further and bind your grid to a 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;