Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm trying to have a textbox select all the text whenever a textbox control gets focus.

 

Code below works when the control gets focus via tab but when clicked it does not. When debugging, this event occurs but nothing happens, possibly because it occurs before the click is processed. Also does not work if I use TextBox1.Click event.

 

Any suggestions??

 

Private Sub TextBoxEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles TextBox1.Enter

   DirectCast(sender, TextBox).SelectAll()

End Sub

  • *Experts*
Posted
Have you tried also handling the Click event to do this? Although traditionally when doing things such as data entry, clicking on the textbox does not cause the text to all be selected.
  • *Experts*
Posted

Why are you having to do this? On my system (Windows XP) this is the default behavior. That is, tabbing into a textbox autoselects everything the first time through. Only on subsequent passes does it change.

 

As Volte pointed out, traditionally, tabbing in should auto-select but clicking should not. For that behavior, using the Enter event would be perfect.

 

But who knows what your users want? I'm glad you found a solution that they like :)

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...