Visual Basic SELECTALL question...

Discussion in 'OT Technology' started by elevator, Mar 5, 2007.

  1. elevator

    elevator The tenants think it's wonderful! ヽ(´ OT Supporter

    Joined:
    Mar 25, 2005
    Messages:
    10,967
    Likes Received:
    0
    Location:
    Houston, TX
    So I want my field to select all when I tab into it BUT when I put Me.txtIP1.SelectAll() in the GotFocus sub, I can only type one character in the field because it selects it when the field has focus and just keeps replacing the character when I type another one.

    Code:
     
    [SIZE=2]Private[/SIZE][SIZE=2]Sub[/SIZE][SIZE=2] txtIP1_GotFocus([/SIZE][SIZE=2]ByVal[/SIZE][SIZE=2] sender [/SIZE][SIZE=2]As[/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2]ByVal[/SIZE][SIZE=2] e [/SIZE][SIZE=2]As[/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2]Handles[/SIZE][SIZE=2] txtIP1.TextChanged
    [/SIZE][SIZE=2]Me[/SIZE][SIZE=2].txtIP1.SelectALL()[/SIZE]
    [SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
    [/COLOR][/SIZE]
     
  2. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    Code:
    Private Sub TextBox2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.GotFocus
        TextBox2.SelectAll()
    End Sub
    That method will work, and on tab it selects everything, but as you type it doesn't keep doing it.
     
  3. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    your probem is your Sub declaration... Check the very end... You have the event handling the "TextChanged" event.. which will cause that sub to execute any time the text changes (which explains the behaviour you've described).

    You want it to handle the "GotFocus" event.
     
  4. elevator

    elevator The tenants think it's wonderful! ヽ(´ OT Supporter

    Joined:
    Mar 25, 2005
    Messages:
    10,967
    Likes Received:
    0
    Location:
    Houston, TX
    :love:

    thank you, i didnt even scroll over to see that I forgot to change it!
     

Share This Page