Datagridview不更新/刷新 [英] Datagridview not updating/refreshing

查看:690
本文介绍了Datagridview不更新/刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGridView由一个来自DB的表的DataSet组成。当我删除一行时,它会在数据库中更新,但不会从GridView中删除。只有当我重新启动应用程序时,它才会从GridView中移除。



请帮忙

解决方案<这是一个非常简单的过程。


1)创建一个绑定源

2。)将此对象的数据源设置为您的数据集表。



3.)将DatagridView的数据源设置为绑定源对象。


代码示例:

  Dataset ds = new Dataset(); 
BindingSource bs = new BindingSource()
bs.Datasource = ds.Table [0];
DatagridView.Datasource = bs;

现在,您在DataTable中所做的任何更改都会自动影响到您的GridView。


I have a DataGridView made of a DataSet of a table from the DB. When I delete a row, it is updated in the database but it is not removed from the GridView. Only when I restart the application does it get removed from the GridView.

Please help

解决方案

This is a very simple process.

1.) Create a Binding Source

2.) Set the Datasource for this object to your Dataset Table.

3.) Set The datasource for your DatagridView as the Binding source Object.

Code Example:

Dataset ds = new Dataset();
BindingSource bs = new BindingSource()
bs.Datasource = ds.Table[0];
DatagridView.Datasource = bs;

Now, Any changes you make in the DataTable will ripple through to your GridView automatically.

这篇关于Datagridview不更新/刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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