刷新按钮 - 插入、删除、更新后刷新数据网格视图 [英] Refresh button - Refreshing data grid view after inserting, deleting, updating

查看:36
本文介绍了刷新按钮 - 插入、删除、更新后刷新数据网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个刷新按钮,以便在完成更新后自动刷新我的 datagridview 中的数据.

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

但是,我的刷新按钮似乎不起作用.显示的数据与原始数据相同.只有在我手动结束 Windows 应用程序并重建它后才会更新.

However, my refresh button doesn't seem to work. The data displayed remains the same as the original one. It only gets updated after i manually end my windows app and rebuild it.

这是我的代码:

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

请帮忙.谢谢^_^

推荐答案

处理此问题的最简单方法是使用 Binding Source 对象.

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

如果您将信息从 Access 数据库加载到 DataGridView 中,那么您最有可能将数据存储在数据集或数据表中.

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

创建绑定源对象,并在填充数据表/数据集后,将绑定源的数据源设置为数据表.然后将 DataGridView 中的 Datasource 设置为 Binding Source 对象.

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.

这样做可确保您的 datagridview 中的任何更改或反映在 DataTable 中,反之亦然.如果您将数据重新加载到 DataTable 中,它将自动反映在数据网格中.

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.

这篇关于刷新按钮 - 插入、删除、更新后刷新数据网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆