How to refresh datagridview in window application
Loading
How to refresh datagridview in window application
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajanikant HawaldarPosted Jul 20, 2022, 6:21 AM
Shivam PayasiPosted Jul 20, 2022, 6:23 AM
Hello, Manju Jd I think you are performing some insert or update operation on the data table after that you want to see the updated DataGridView.
now you need to create a method Named LoadData() or RefreshGrid() whatever you want it's your choice
and this method contains code
private void RefreshGrid()
{
con = db.connection();//Here you can simply add your connection
con.Open();
SqlDataAdapter sd = new SqlDataAdapter("select *from TblDept",con);//write your Query to get data
dataGridView1.DataSource = null;//this is the main Part Here you need to clean all data that was presented in the Grid
DataSet ds = new DataSet();
sd.Fill(ds, "TblDept");
dataGridView1.DataSource = ds.Tables[0];//Now here we are Reloading the Gtrid
}
Here in this method we are removing all Old data from GridView and Adding Updated data on the Grid You can use your
own code to load data on GridView Important part is to remove All data from the grid by
dataGridView1.DataSource = null;
and Reload GridView With your Data
you just need to call this method whenever you need to Refresh the GridView it will work.
Thanks.. for Your Query
Amit MohantyPosted Jul 20, 2022, 5:03 AM
Vishal YelvePosted Jul 19, 2022, 7:16 PM