DataGridView bound to a Dictionary and updated with a thread
- by Manjoor
I have a Dictionary binded to DataGridView by using following sample code.
http://stackoverflow.com/questions/854953/datagridview-bound-to-a-dictionary
Please see the above question first
The diffrence is that i am updating dictionary from a thread. (Event handler of another class).
My Event handler is as below
static void f_PriceChanged(Objet f, eventData e)
{
if (prices.ContainsKey(e.ItemText))
prices[e.ItemText] = e.price;
else
prices.Add(e.ItemText, e.price);
}
Not to mention the prices is declared as class level.
I have modified the button code from original post as
Button btn = new Button();
btn.Dock = DockStyle.Bottom;
btn.Click += delegate
{
bl.Reset();
};
form.Controls.Add(btn);
Internally the Dictionary is updated as expected but grid does not update. Clicking on button generate exception
Collection was modified; enumeration operation may not execute
What to do?