How to Display Dynamically Updated Binding List in DataGridView
Introduction
Binding a List
Problem
Consider a scenario with a List
Solution
Using a BindingList
The DataGridView does not maintain a direct connection to a List
var list = new BindingList<Person>(persons); myGrid.DataSource = list;
Using a BindingSource
For more granular control, consider using 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 BindingSource provides flexibility for data manipulation and binding multiple data sources. Changes to the underlying data are propagated to the grid without explicit rebinding.
The above is the detailed content of How to Keep a DataGridView Updated When Binding to a Dynamic List?. For more information, please follow other related articles on the PHP Chinese website!