我们正在绑定一个DataGridview
using BindingSource
。所以在主线程中我们是这样给出的。
class1BindingSource = new BindingSource();
class1BindingSource.DataSource = class1List;
this.dataGridView1.DataSource = class1BindingSource;
之后,我在表单中放置了一个后台工作人员,并通过单击按钮触发。
即在按钮中单击
this.backgroundWorker1.RunWorkerAsync()
In the BackgroundWorker
DoWork Event
我正在尝试更新BindingSource
并尝试更新DataGridview
.
So the BindingSource
重置是在另一个类的方法中完成的。
DoWork Event
Class2 cl2 = new Class2();
cl2.UpdateBindingSource(class1BindingSource);
UpdateBindingSource Method
public void UpdateBindingSource(BindingSource bs)
{
Class1 c1 = bs.Current as Class1;
for (int i = 0; i < 1000; i++)
{
lock (bs.SyncRoot)
{
c1.MyProperty1 = i;
bs.ResetItem(0);
}
}
}
现在我遇到了一个异常,比如BindingSource
不能是其自己的数据源。不要设置DataSource
and DataMember
属性到引用回的值BindingSource
.
如果我在我的DoWork Event
然后我可以使用重置控制线程本身中的项目BeginInvoke method
.
但实际上我是在尝试模拟我们的应用场景。所以我想以这种格式解决这个问题。
谁可以帮我这个事。