|
-
Dec 9th, 2004, 10:02 AM
#1
Re: Capturing when ANY textbox on a form has changed..
wow you guys really have to explore the power of .NET
only Asgorath was on the right track to tackle this problem..
one of the really cool features of .NET, is the ability to add handlers for events, and an even can have more than 1 handler...
observe:
I have a data entry app, that I only want to prompt the user to save changes, if in fact something has changed.
Code:
Private Sub AddSaveHandlers(ByVal c As Control)
For Each ctrl As Control In c.Controls
If ctrl.Controls.Count > 0 Then
AddSaveHandlers(ctrl)
End If
Select Case ctrl.GetType.Name.ToUpper
Case "TEXTBOX", "COMBOBOX"
AddHandler ctrl.TextChanged, AddressOf SetPromptSaveTrue
Case "CHECKBOX"
AddHandler CType(ctrl, CheckBox).CheckStateChanged, AddressOf SetPromptSaveTrue
Case "RADIOBUTTON"
AddHandler CType(ctrl, RadioButton).CheckedChanged, AddressOf SetPromptSaveTrue
End Select
Next
End Sub
Private Sub SetPromptSaveTrue(ByVal sender As System.Object, ByVal e As System.EventArgs)
mPromptSave = True
End Sub
in the "Windows Form Designer generated code" Sub New where it says "'Add any initialization after the InitializeComponent() call" I put
AddSaveHandlers(Me)
this function is recusive in that if you have any container controls, like groupboxes, pictureboxes, panels, etc.. it will add the handler to all the controls contained in them as well
-
Dec 9th, 2004, 10:03 AM
#2
Re: Capturing when ANY textbox on a form has changed..
you can then also add specific per control handlers.. even for the same TextChanged or CheckStateChanged events.. just like you normally would, and they will work in conjunction with these dynamic handlers
-
Dec 9th, 2004, 10:04 AM
#3
Thread Starter
Hyperactive Member
Re: Capturing when ANY textbox on a form has changed..
Kleinma,
That's %$(*ing perfect. Thanks for that, it's obvious (now that I see it )
--Ben
-
Dec 9th, 2004, 10:14 AM
#4
Hyperactive Member
Re: Capturing when ANY textbox on a form has changed..
That is a great idea kleinma. I don't know why that never crossed my mind. I use that alot when it comes to dynamically creating controls, but never once thought to do it on controls I created in design time. I will have to keep that in mind next time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|