Selected Text

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

I am wanting to select all of the text in a textbox control when the enters
the control I thought the "selectionLength" property and setting it to the
length of the value in the textbox. I also used the "entered" event. Nothing
happens when I enter the control. The code (below) executes, but nothing is
highlighted like is was selected. Am I not using the correct property?

Thanks in advance for your assistance!!!!
 
TextBox1.SelectionStart = 0
TextBox1.SelectionLength = TextBox1.Text.Length

TextBox1.Focus()

HTH
Kalpesh
 
Jim Heavey said:
I am wanting to select all of the text in a textbox control when the
enters the control I thought the "selectionLength" property and
setting it to the length of the value in the textbox. I also used
the "entered" event. Nothing happens when I enter the control. The
code (below) executes,

Hmm..pretty fast code... ;-)
but nothing is highlighted like is was
selected. Am I not using the correct property?

TextBox1.SelectAll()



works for me. It doesn't help when entering the texbox using the mouse
because the selection is set after the textbox has been entered.
 
Hello,

Jim Heavey said:
I am wanting to select all of the text in a textbox control when the enters
the control I thought the "selectionLength" property and setting it to the
length of the value in the textbox. I also used the "entered" event. Nothing
happens when I enter the control. The code (below) executes, but nothing is
highlighted like is was selected. Am I not using the correct property?

Where is the code?

Untested: Use this class instead of the standard windows forms textbox:

\\\
Public Class MyTextBox
Inherits TextBox

Private Sub MyTextBox_GotFocus( _
ByVal sender As Object, _
ByVal e As System.EventArgs _
) Handles MyBase.GotFocus
Me.SelectAll()
End Sub
End Class
///

HTH,
Herfried K. Wagner
 
Back
Top