I'm using a datagridView, that it is bound to a bindingsource
,
this binding source is array of List<MyClass>
.
The bindingsource
is constantly update from other threads(every 100 milliseconds).
* other threads can remove, add or update the bindingsource in any give time.
1) The bindingsource.Remove(object)
method is not removing the object because the properties values are different, so there is no match for remove to work.
2) The bindingsource.RemoveAt(int)
do remove the object, but is some case the wrong object because the bindingsource
index is keep changing by other threads updates.
Can I remove an object from the bindingsource
by property name? Or
how to remove the right object?
The below code is the non-working RemoveAt
dataGridView_manage_positions.SuspendLayout();
var position = GetPosition(uniqueID);
int index = 0;
for (int i = 0; i < _bindingSource_manage_grid.Count; i++)
{
var row = (MyClass)_bindingSource_manage_grid[i];
// EXAMPLE: the row.Net = 1.52
if (row.ID != position.ID)
continue;
dataGridView_manage_positions.BeginInvoke(new Action(() =>
{
// this the problem. HERE i have a race condition
// EXAMPLE: the row.Net = 2.56
// now the Remove() will not work, because the object value is different
_bindingSource_manage_grid.Remove(row);
}));
break;
}
dataGridView_manage_positions.ResumeLayout();
Thanks!!!!!