none
Select All (Ctl-A) fires TextChanged Event of TextBox control RRS feed

  • Question

  • I have a form with several Textboxes.

    The form has logic that enables/disables navigation buttons when any of the TextBoxes have data that is changed by the user. This forces the user to select whether to Save or Undo-Changes before navigating to another record in the underlying table.

    Sometimes I need to copy the data from one of the TextBoxes into another app (such as an email message).
    When I click on the field and then Ctl-A (i.e. Select-All), it fires off the TextChanged event which makes the form "think" that it "IsDirty" in Access parlance. However, if I simply click on the field and then 1). Press the <End> key, 2) Hold the <Shift> down and press the <Home> key...which also simulates the same as Ctl-A, the text is selected, but the TextChanged event is not fired.

    Does anyone know why?

    Thanks for your time in advance.

    Paul Goldstein


    Paul D. Goldstein Forceware Systems, Inc.

    Tuesday, October 31, 2017 2:35 AM

All replies

  • Hi Paul,

    Based on your description, Ctrl + A fired TextChanged event, if I just input Ctrl, this event is not fired, so I think the "A" key can be capture by Textbox and it may change TextBox content, and TextChanged event is fired.

    The End + Shift + Home key or Home + Shift + End key are use to select char from start location to end location, these key can not change TextBox content, so the TextChanged event will not be fired.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 1, 2017 6:10 AM
    Moderator
  • I did a test with EN_CHANGE : it is not fired with [Ctrl+A]

    (VS 2015, Windows 10)

    Wednesday, November 1, 2017 6:40 AM
  •  You can handle the KeyDown event of the TextBoxes to suppress the key and select all the text yourself.

        Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
            If e.Control AndAlso e.KeyCode = Keys.A Then
                e.SuppressKeyPress = True
                TextBox1.SelectAll()
            End If
        End Sub
    
     


    If you say it can`t be done then i`ll try it

    • Proposed as answer by dbasnett Wednesday, November 1, 2017 1:24 PM
    Wednesday, November 1, 2017 8:23 AM
  •  You can handle the KeyDown event of the TextBoxes to suppress the key and select all the text yourself.

        Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
            If e.Control AndAlso e.KeyCode = Keys.A Then
                e.SuppressKeyPress = True
                TextBox1.SelectAll()
            End If
        End Sub
     


    If you say it can`t be done then i`ll try it

    Great workaround!

    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it" - MSDN User JohnWein

    Wednesday, November 1, 2017 1:47 PM