Refresh button - Refreshing data grid view after inserting, deleting, updating

前端 未结 6 1641
别跟我提以往
别跟我提以往 2020-12-02 00:59

I\'m trying to create a refresh button to automatically refresh the data inside my datagridview after i have finish updating them.

However, my refresh button doesn\'

6条回答
  •  余生分开走
    2020-12-02 01:28

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

    If your loading information into your DataGridView from an Access Database then your most likely storing the Data in a Dataset or DataTable.

    Create a Binding Source object, and once you have populated your DataTable/Dataset, set the datasource for your Binding Source to your DataTable. Then set the Datasource from the DataGridView as the Binding Source object.

    Doing this ensures that any changes in your datagridview or reflected in the DataTable and vice Versa. If you reload data into your DataTable it will reflect in the Data Grid Automatically.

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

    All changes will now happen automatically.

提交回复
热议问题