简体   繁体   English

C#值更改时刷新数据集

[英]C# Refresh DataSet When Value Changed

I'm trying to make a responsive DataGridView table but I'm having some difficulties when updating the value of the field. 我正在尝试制作一个响应式DataGridView表,但是在更新字段的值时遇到了一些困难。 If I edit the field, leave it out and press on a refresh button - all works out. 如果我编辑该字段,则将其保留,然后按刷新按钮-全部解决。 If I use one of the triggers like CellValueChanged or `CellEndEdit' I get an error 如果我使用像CellValueChanged或`CellEndEdit'这样的触发器之一,则会收到错误消息

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll

Additional information: Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.


private void Sync()
{
SqlCommandBuilder cmdr = new SqlCommandBuilder(prekes);
prekes.Update(d.Tables["Prekes"]);
Refresh();
}

private void Refresh()
{
dataGridView1.AutoGenerateColumns = false;
d = new DataSet();
prekes.Fill(d, "Prekes");
dataGridView1.DataSource = d.Tables[0];
}

dataGridView1.DataSource = d.Tables[0]; dataGridView1.DataSource = d.Tables [0]; is where I get the error.. 是我得到错误的地方。

Please note that I'm getting that error only when I click around, few first times it works just fine. 请注意,只有在我单击鼠标时才会收到该错误,很少有几次它可以正常工作。 Should I try to catch and exception or something when that happens and ignore it? 我是否应该尝试捕获并例外或发生什么事情而忽略它? Or should I use another trigger not CellEndEdit ? 还是应该使用其他触发器而不是CellEndEdit?

try the following code snippet in your refresh method 在您的刷新方法中尝试以下代码片段

prekes.Clear();//dataset.clear
    dataAdaoter.Fill(prekes);//DataAdapter.Fill

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM