I can't explain this with my own words, so here's the situation:
myBindingSource.Add(new myElement());
SetDataSource(myBindingSource);
myBindingSource.Add(new myElement());
I always catch an exception (a cross-thread exception) on the second call of Add. Here's the SetDataSource void:
delegate void SetDataSourceCallback(BindingSource db);
private void SetDataSource(BindingSource db)
{
if (myDataGridView.InvokeRequired)
{
SetDataSourceCallback d = new SetDataSourceCallback(SetDataSource);
myDataGridView.Invoke(d, new object[] { db });
}
else
{
myDataGridView.DataSource = db;
}
}
I can't understand why this keep happening!