DataGridView bound to a Dictionary and updated with a thread

Posted by Manjoor on Stack Overflow See other posts from Stack Overflow or by Manjoor
Published on 2010-04-08T09:08:04Z Indexed on 2010/04/08 9:13 UTC
Read the original article Hit count: 320

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about data