Results 1 to 4 of 4

Thread: Problem with t.SelectAll()

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Problem with t.SelectAll()

    I am trying to write a sub that would select (highlight) the default values of my text boxes as they are entered.

    Here is the code. For some reason the default value is not being highlighted when I mouse into a textbox. It does, however do so when I tab into it but I think it does that by default. What is wrong with my code or technique?
    VB Code:
    1. Private Sub txtOvtAc1_Enter(ByVal sender As Object, ByVal e _
    2.         As System.EventArgs) Handles txtOvtAc1.Enter, _
    3.             txtOvtAc2.Enter, txtOvtAc3.Enter, txtOvtAc4.Enter, _
    4.             txtOvtAf2.Enter, txtOvtBrh.Enter, txtOvtCar.Enter, _
    5.             txtOvtCpt.Enter, txtOvtFin.Enter, txtOvtLab.Enter, _
    6.             txtOvtLat.Enter, txtOvtPla.Enter, txtOvtSflr.Enter, _
    7.             txtOvtSpy.Enter, txtOvtTil.Enter, txtRegAc1.Enter, _
    8.             txtRegAc2.Enter, txtRegAc3.Enter, txtRegAc4.Enter, _
    9.             txtRegAf2.Enter, txtRegBrh.Enter, txtRegCar.Enter, _
    10.             txtRegCpt.Enter, txtRegFin.Enter, txtRegLab.Enter, _
    11.             txtRegLat.Enter, txtRegPla.Enter, txtRegSflr.Enter, _
    12.             txtRegSpy.Enter, txtRegTil.Enter
    13.  
    14.         Dim t As TextBox
    15.         t = sender
    16.         t.SelectAll()
    17.         t.BackColor = Lavender
    18.  
    19.     End Sub
    By the way the backcor is being changed as expected.

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    eek , the handler looks a little long , maybe you should look into the AddHandler function , anyway , you need to set the HideSelection property to false on your textbox when selecting all.
    try this ...
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim ctl As Control
    3.         For Each ctl In Controls
    4.             If ctl.GetType.IsAssignableFrom(GetType(TextBox)) Then
    5.                 AddHandler ctl.Enter, AddressOf TextBox_Enter
    6.             End If
    7.         Next
    8.     End Sub
    9.  
    10.     '/// handle all the textbox enter calls in this simple sub...
    11.     Private Sub TextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs)
    12.         Dim tb As TextBox = DirectCast(sender, TextBox)
    13.         tb.HideSelection = False
    14.         tb.SelectAll()
    15.     End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3
    Lively Member mindloop's Avatar
    Join Date
    Mar 2004
    Posts
    64
    try ctype :
    VB Code:
    1. Dim t As TextBox
    2.         t = cype(sender, textbox)
    3.         t.BackColor = Lavender
    4.         t.SelectAll()
    ehmm...

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354
    Thank you both. The HideSelection = False seemed to work just fine.

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