[ACCEPTED]-How to refresh the DataSource on a WinForms DataGridView?-refresh

Accepted answer
Score: 13

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"

Score: 7

The answer is to have the gridview connected 1 to the BindingList rather than the List.

Score: 2

This works for me:

dataGridView.DataSource = null;
dataGridView.DataSource = listOfSomething;


More Related questions