Bind a List to a DataGridView which is filled by an other thread

In .NET v1.1 I already tried to implement a List that tells the DataGrid that it was updated. I managed this through deriving a class from System.Collections.CollectionBase and overriding a bunch of Methods. The Problem was whenever I chaned a property of an item which was already added to this list nothing was updated. I had to implement Events and update the List on my own. Everything was connected and everytime I wanted to use the list for an other Item Type I had to write a lot lines of code. What a waste of time.

Then a few days ago I took a look at Visual Studio 2005 Beta2 and discovered a Class named BindingList which will inform the databinding Control that itself is updated. Besides it is a generic list which makes that thing more type-safe.
I bound the list to a DataGridView and added some items. To cause an update when a bound item's property is changed I had to implement System.ComponentModel.INotifyPropertyChanged Interface. This Interface delivers the PropertyChanged event which informs the databinding control that itself was changed. I think this is a dirty solution but better than .NET v1 in any way.
I implemented the Interface on all objects and raised the event delivered whenever I changed a property. Great job! Everything worked fine!

I didn't care about that thing anymore because it worked fine and integrated it into my application. But I didn't think that multi-threading is such a heavy problem for this Microsoft guys because everytime an item was changed by an other thread I got an exception. Fortunatelly I already implemented a Service which provides UiSafety so I simply had to call this service before I rose the event and my list were updated correctly.

I think noone will talk about in any TechTalk or PDC but in my oppinion it is a great feature saving a lot lines of code although you have to care for thread safety on your own. Good job Microsoft!

Comments

Popular posts from this blog

Custom Chrome in WPF

Capture WebCam with WinForms2

InstallShield Applications on Vista 5270