Click here to Skip to main content
15,887,998 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
We want to refresh datagridview (displaying on screen) as soon as user makes any changes to the database table (binded with that datagridview) by clicking a Refresh button after any of above said operations.

How to do this?
Posted
Updated 16-May-11 21:56pm
v2
Comments
Dalek Dave 17-May-11 3:56am    
Edited for Readability.

Hi,

Please refer to the following post: How to insert, update, delete using DataGrid .. The post describes how to go about performing the actions you require.

Kind regards,
 
Share this answer
 
Thanks for your reply but actually my requirement is only to refresh DataGridView on each database table's change through btnClick() event.
 
Share this answer
 
Comments
Programm3r 17-May-11 4:15am    
The datagridview is bound to a local snapshot copy of the records in the database(not the database iteself), these are what is stored in the dataset.

However when your form updates the database, it doesnt automatically update the local snapshot copy of the records(dataset).

In order to do this you would need to repopulate the dataset by re-executing the Fill method to repopulate the dataset with the newly updated database records.
parmar_punit 17-May-11 5:20am    
Do this...
Just Fire a query and Bind your GridView in the method of Refresh button's click as you bound your gridview in FormLoad...
What you need to do is create a Refresh method that updates your Data Source and then rebinds to the DataGrid.
Here is an outline of how I would go about it

C#
public partial class MainWindow : Window
    {
        private List<yourItems> listItems;
        public MainWindow()
        {
            InitializeComponent();
            listItems = new List<yourItems>();
            Refresh();
        }
        private void Refresh()
        {
            listItems = DataAccess.GetData();
            DataGridView1.DataSource = listItems;
        }
        private void button1_click(object sender, EventArgs e)
        {
            Refresh();
        }
}


Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900