Results 1 to 14 of 14

Thread: Capturing when ANY textbox on a form has changed..[RESOLVED]

Hybrid View

  1. #1
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297

    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

  4. #4
    Hyperactive Member
    Join Date
    Jun 2002
    Location
    midewest u.s.
    Posts
    275

    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
  •  



Click Here to Expand Forum to Full Width