Refresh button - Refresh the data grid after inserting, deleting, updating

I am trying to create an update button to automatically update the data inside my datagridview after I finish updating it.

However, my refresh button does not work. The displayed data remains the same as the original. It only updates after I manually exit the Windows application and restore it.

Here is my code:

private void button_refresh_Click(object sender, EventArgs e) { this.acuzioSecureStore_DatabaseXDataSet.AcceptChanges(); } 

Help. thanks ^ _ ^

+4
source share
6 answers

The easiest way to handle this is to use the Binding Source object.

If you load information into your DataGridView from an access database, you most likely save the data in a dataset or DataTable.

Create a binding source object, and once you populate your DataTable / Dataset, set the data source for your binding source to your DataTable. Then set the data source from the DataGridView as the binding source object.

Doing this ensures that any changes to your datagridview are either reflected in the DataTable and vice versa. If you reload the data into your DataTable, it will automatically be reflected in the data grid.

 DataTable dt = new DataTable(); BindingSource bs = new BindingSource(); bs.DataSource = dt; dataGridView1.DataSource= bs; 

All changes will now be performed automatically.

+4
source

Hi, the solution above is good, but when the code above is executed, the table disappears and is not visible. And if I do

  da.Fill(ds, "p"); dataGridView1.DataSource = ds.Tables["p"]; 

then the whole table will be created again.

0
source
 private void button_refresh_Click(object sender, EventArgs e) { SqlConnection con=new SqlConnection(@""); string query="select * from abc"; SqlCommand cmd=new SqlCommand(query,con); SqlDataAdapter da=new SqlDataadapter(cmd); DataTable dt=new DataTable(); da.Fill(dt); dataGridView1.DataSource=dt; } 
0
source

I had a datagridview related to a table in an Entity Framework database:

 dataGridView1.DataSource = MyDatabase.MyTable; 

It will never be updated, despite two wasted days. I solved this with a simple workaround:

 private void button_refresh_Click(object sender, EventArgs e) { dataGridView1.DataSource = MyDatabase.MyTable.Where(i =>(true)); } 

This is an ugly workaround, and a friend explained to me how it works - if I just dataGridView1.DataSource = database.table , it will cache the table and use cached data forever. The fact that every time we create a new dummy request prevents .net caching.

0
source

Please try this, it worked for me and will tell me if you have a better option.

 private void button3_Click(object sender, EventArgs e) { dataGridView1.Refresh(); } 
0
source

you can bind dataGridView to load on the Load or UserControl page and after chage in the form of a grid Raise the load event

as

this.ucUsers_Load (null, null); // Windows From C #

0
source

All Articles