[ACCEPTED]-How to refresh the DataSource on a WinForms DataGridView?-refresh
Accepted answer
OLD ANSWER: Did you try calling GridView.DataBind()?
Woops, I 6 thought this was a WebForms DataGrid.
If 5 you're on WinForms, you might want to look 4 into the BindingSource class. Binding to 3 that class instead of straight to your list 2 will provide update notification, etc.
The 1 following code works for me:
List<Person> names = new List<Person>();
names.Add(new Person(){
FirstName = "Steve",
LastName = "Jobs"
});
names.Add(new Person()
{
FirstName = "Bill",
LastName = "Gates"
});
BindingSource source = new BindingSource();
source.DataSource = names;
dataGridView1.DataSource = source;
names.Add(new Person()
{
FirstName = "Steve",
LastName = "Balmer"
});
source.ResetBindings(false);
The answer is to have the gridview connected 1 to the BindingList rather than the List.
This works for me:
dataGridView.DataSource = null;
dataGridView.DataSource = listOfSomething;
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.