3 回答
TA贡献1836条经验 获得超13个赞
列表未实现,IBindingList因此网格不知道您的新项目。
将DataGridView绑定到一个BindingList<T>。
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;
TA贡献1880条经验 获得超4个赞
每次向List添加新元素时,都需要重新绑定Grid。就像是:
List<Person> persons = new List<Person>();
persons.Add(new Person() { Name = "Joe", Surname = "Black" });
persons.Add(new Person() { Name = "Misha", Surname = "Kozlov" });
dataGridView1.DataSource = persons;
// added a new item
persons.Add(new Person() { Name = "John", Surname = "Doe" });
// bind to the updated source
dataGridView1.DataSource = persons;
- 3 回答
- 0 关注
- 1465 浏览
添加回答
举报