DataGridView,PONO,Update from a Background Thread; Oh My

Problem:Update DataGridView from a background thread. The update will be published from a PONO (Plain Old DotNet Object) PropertyChanged event (INotifyPropertyChanged). When the PONO changes it fires one or more PropertyChanged events through the INotifyPropertyChanged interfaces. Sounds like an easy problem, so… it should just work? Right? It didn’t. Not for me. Possible Solutions:

  1. I had an array full of the PONO. I thought I should just be able to set the DataSource of the DataGridView to my PONO array. It does load the data that is in the PONO array when the DataSource is set, but it did not update the data as PropertyChanged events were fired. What?
  2. Assign the array to a BindingSource before assigning the BindingSource to the to the DataSource property of the DataGridView. Once again, this loads the data, but the data is not updated when the event(s) are fired.

Real Solution:Convert my array of PONO to a BindingList, then assign it to the DataSource of either a BindingSource or the DataGridView. This worked. Now when a PropertyChanged event is fired the grid updates correctly. I am guessing that the DataGridView and BindingSource don’t listen for PropertyChange events. The BindingList does listen for the event and when it occurs, it tells the Grid to update. Hopefully this will help someone else, as it took about a half day away from me.

Advertisements

3 Responses

  1. You did help me in pointing my attention to the INotifyPropertyChanged interface. Implementation of that put me back in business. Thanks.

  2. I have this solution working as well but have run into a problem. If i have a list of, say 200 items, and they are all updating every 50 milliseconds AND i click grag to select a bunch of rows, i get a Cross Thread Operation Not Valid exception. Did you hit this snag?

  3. No. Not that I recall. Sorry. Let me know if you find a solution.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: