We are binding a DataGridview
using BindingSource
. So in the main thread we have given like this.
class1BindingSource = new BindingSource();
class1BindingSource.DataSource = class1List;
this.dataGridView1.DataSource = class1BindingSource;
After that i have a placed a background worker in the form and is triggering in a button click.
i.e. in the button click
this.backgroundWorker1.RunWorkerAsync()
In the BackgroundWorker
DoWork Event
i am trying to update the BindingSource
and there by trying to update the DataGridview
.
So the BindingSource
reset is done in a method in another class.
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);
}
}
}
Now i am getting an exception like BindingSource
cannot be its own data source. Do not set the DataSource
and DataMember
properties to values that refer back to BindingSource
.
If i am doing this in my DoWork Event
then i can reset the item in the control thread itself using BeginInvoke method
.
But actually i am trying to simulate our application scenario. So i want to solve this in this format.
Can any one help me on this.