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

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

问题描述

我试图创造一个刷新按钮后,我已完成更新其自动刷新我的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.

下面是我的code:

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

请协助。谢谢^ _ ^

Please assist. thanks ^_^

推荐答案

来处理最简单的方法是使用绑定源对象。

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

如果您加载信息到你的DataGridView从Access数据库那么你极有可能存储在数据集或数据表数据。

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

创建一个绑定源对象,一旦你已经填充了数据表/数据集,设置数据源为您绑定源到你的数据表。然后在DataGridView作为绑定源对象设置数据源。

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或体现在数据表中,反之亦然任何更改。如果您重新加载数据到数据表中,将在数据网格反映自动。

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天全站免登陆