Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh DataGridView

Tags:

c#

winforms

I have a dataGridView bound to a table. On the same form as the DataGridView I have a few textboxes and a button to add new values to the database and want them displayed in the gridView too. Saving in the database works, just the new values are not shown in the gridView. I have tried the following:

this.Validate();
this.pBindingSource.EndEdit();
this.pTableAdapter.Update(this.DBDataSet);
pDataGridView.Refresh();

This didn't work. From my understanding the .Refresh method only redraws the GridView, so it should work after updating the tableAdapter, so I thought. But it doesn't.

Then I've tried:

this.pDataGridView.DataSource = null;
this.pDataGridView.DataSource = this.pBindingSource;
pDataGridView.Refresh();

which doesn't work either. Then tried to ResetBindings() for the binding source, which didn't work, and then I ran out of ideas.

How to refresh the DataGridView?

like image 764
orzac sergiu Avatar asked Jun 16 '26 10:06

orzac sergiu


1 Answers

You can modify like

this.pDataGridView.DataSource = null;
this.pDataGridView.DataBind();
this.pDataGridView.DataSource = this.pBindingSource;
pDataGridView.DataBind();
like image 189
Sree Avatar answered Jun 17 '26 23:06

Sree