DataGridView bound with iNotifyPropertyChanged object question
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.
开发者_JS百科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.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.
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).
I think you want to handle the BindingSource.CurrentItemChanged
event.
精彩评论