How to handle a propertyvaluechanged event ( or any event) correctly?
-
Hi, I have the following problem and I am wondering what the general way is to fix this. I have got a form with an edit and a store button and a customized propertygrid for the user to capture some information. The thing I want to have is that when the user changes a property value in the propertygrid the store button changes from disabled to enabled. I don't want the eventhandler main event handler on the form. I currently have the propertyvaluechanged handler on the customized propertygrid. The form I am using is also a derived form from the standard one. I guess the simple solution would be to create the handler on the form and have the enabled switch in this handler, but then you would have to re-create this routine each time so I am looking for something a bit more generic. Keep in mind that I am still learning a lot about vb, so a solution that you think would be pretty obvious, could very well be completely unknown to me..... Thanks in advanced :confused: Think, try, think, think, try, think, think, think, try, ASK, think, try, advance on step and start over...
-
Hi, I have the following problem and I am wondering what the general way is to fix this. I have got a form with an edit and a store button and a customized propertygrid for the user to capture some information. The thing I want to have is that when the user changes a property value in the propertygrid the store button changes from disabled to enabled. I don't want the eventhandler main event handler on the form. I currently have the propertyvaluechanged handler on the customized propertygrid. The form I am using is also a derived form from the standard one. I guess the simple solution would be to create the handler on the form and have the enabled switch in this handler, but then you would have to re-create this routine each time so I am looking for something a bit more generic. Keep in mind that I am still learning a lot about vb, so a solution that you think would be pretty obvious, could very well be completely unknown to me..... Thanks in advanced :confused: Think, try, think, think, try, think, think, think, try, ASK, think, try, advance on step and start over...
In your inherited control override the protected sub OnPropertyValueChanged:
Protected Overrides Sub OnPropertyValueChanged(ByVal e As System.Windows.Forms.PropertyValueChangedEventArgs) 'Put your code here to fire when the property is changed 'Make sure you call the base method you are overriding MyBase.OnPropertyValueChanged(e) End Sub
In the base class (Windows.Forms.PropertyGrid) this method will simply fire the PropertyValueChanged event, by overriding the sub you can 'slip' your own code in before the event is fired. More info on this method is available on MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformspropertygridclassonpropertyvaluechangedtopic.asp[^] It is worth investigating these protected methods when you inherit from other classes. Hope this helps Tom