|
-
Dec 9th, 2004, 10:02 AM
#6
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
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
|