views:

36

answers:

3

I have a derived DataGridView bound to a BindingList, and the object implements iNotifyPropertyChanged.

I'd like to do the following: When my a property attached to my DataGridView is changed, I want to call a function that will update the header of one of my columns.

Basically, I want to add my OWN response to the PropertyChanged event. Unfortunately, I cannot find where the hook\handle is for the event to subscribe to it myself.

Thanks in advance!

Edit:
The solution I took was a hybrid between the top two answers. I ended up subscribing to the ListAdded\Changed event, and was able to get enough context from there to update all of my functions.

+1  A: 

On the BindingList, look at the ListChanged event.

Edit: http://msdn.microsoft.com/en-us/library/ms132742.aspx says that the event occurs "when the list or an item in the list changes" (i.e., when the PropertyChanged event of the object in the list is fired).

TreDubZedd
Is that the location that responds to the PropertyChanged event?
greggorob64
+1  A: 

I think you want to handle the BindingSource.CurrentItemChanged event.

Arnshea
+1  A: 

You should override following methods: OnDataMemberChanged http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.ondatamemberchanged.aspx OnDataSourceChanged http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.ondatasourcechanged.aspx

Inside these methods you should use ListBindingHelper class http://msdn.microsoft.com/en-us/library/system.windows.forms.listbindinghelper.aspx and his GetList method to get actual object that represents list bound to your DataGridView. You should try to cast it to IBindingList, and if you use .NET FW 3.5 or higher, to INotifyCollectionChanged interface, and subscribe to corresponding events.

STO
Workin in .net 2.0... I'll see how far I can get and check and see if I can grab them from there.I don't necessarily need to figure out exactly what property changed, just as long as I can know for sure that some property changed. If ListChanged gets fired every time, it will do.
greggorob64