如果源有更改,我如何在 c# 中更新 DataGridView

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1209808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 10:59:38  来源:igfitidea点击:

How can i update DataGridView in c# if Source has changes

c#datagridviewdatatabledataset

提问by subprime

i have a Problem with DataGridView in c# and i hope you can help me :) I added a DataGridView to my Application and bind it to DataTable. The DataTable changing the content but the DataGridView doesnt display it... How can i change this ? Thanks

我在 c# 中遇到了 DataGridView 的问题,我希望你能帮助我 :) 我在我的应用程序中添加了一个 DataGridView 并将它绑定到 DataTable。DataTable 更改了内容,但 DataGridView 不显示它...我该如何更改?谢谢

采纳答案by David

Is the data changing at the source, or within the application?

数据是在源头还是在应用程序内发生变化?

If the data is changing at the source, then I think the issue may be that .Net by default supports a disconnected data paradigmwhich is different from using a permanently connected model. Once the data is retrieved from the server, the client is no longer connected unless you go and get the data again. For example, if you're using a TableAdapter, you'd have to periodically call the DataAdapter.Fill() command to retrieve the data from the server.

如果数据在源头发生变化,那么我认为问题可能在于 .Net 默认支持断开连接的数据范式,这与使用永久连接的模型不同。从服务器检索数据后,除非您再次获取数据,否则客户端将不再连接。例如,如果您使用的是 TableAdapter,则必须定期调用 DataAdapter.Fill() 命令以从服务器检索数据。

If the data is changing in your app based on user interaction, then possibly DataDable.AcceptChanges() followed by Application.DoEvents()?

如果您的应用程序中的数据基于用户交互而发生变化,那么可能是 DataDable.AcceptChanges() 后跟 Application.DoEvents()?

回答by Khadaji

Did you try DataGridView.Refresh()?

你试过 DataGridView.Refresh() 吗?

回答by David

grid.dataBind()

网格数据绑定()

回答by jasom

You need use

你需要使用

this.TableAdapter1.Fill(this.DataSet1.zakaznici);

That is usable for me. Try it

那对我有用。尝试一下

回答by sassouki

// clear your dataset
this.dataSet1.Clear();
// refill you dataset
this.dataSet1.ReadXml("data.xml");