Maintaining an Up-to-Date DataGridView with a Binding List
When binding a List
Problem Explanation
A List
Solution
To resolve this issue, bind the DataGridView to a BindingList
Binding to a BindingList
var list = new BindingList<Person>(persons); myGrid.DataSource = list;
Additional Recommendation
Consider using a BindingSource to further enhance data binding capabilities. A BindingSource acts as an intermediary between the data source (BindingList
Binding 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;
The above is the detailed content of How Can I Keep My DataGridView Updated When Using a List?. For more information, please follow other related articles on the PHP Chinese website!