|
-
Feb 7th, 2007, 06:01 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] VB2005 Select value in textbox on formload
Hello,
When my form openes I want the textbox 'txtNumber' to highlight the 1 that is automatically put in there.
I use the following code but it doesnt work.
What am I doing wrong?
VB Code:
Me.txtNumber.Text = 1
Me.txtNumber.Focus()
Me.txtNumber.Select(0, Len(txtNumber.Text))
-
Feb 7th, 2007, 06:09 AM
#2
Re: VB2005 Select value in textbox on formload
Calling Focus on a control in the form's Load event handler has no effect because you can't focus a control on a form that hasn't been displayed. Once the form appears the first control in the Tab order will receive focus regardless. If you want to activate a different control then do it in the Shown event handler, which is executed AFTER the form is displayed.
Also, why set the Text in the Load event handler rather than in the designer?
Finally, use the SelectAll method of a TextBox to select all the text it contains.
-
Feb 7th, 2007, 06:12 AM
#3
Thread Starter
Fanatic Member
Re: VB2005 Select value in textbox on formload
Thank you very very much.
you where very helpfull.
I've learned something and thats important for me.
-
Feb 7th, 2007, 06:16 AM
#4
Re: [RESOLVED] VB2005 Select value in textbox on formload
 Originally Posted by bodylojohn
Hello,
When my form openes I want the textbox 'txtNumber' to highlight the 1 that is automatically put in there.
I use the following code but it doesnt work.
What am I doing wrong?
VB Code:
Me.txtNumber.Text = 1
Me.txtNumber.Focus()
Me.txtNumber.Select(0, Len(txtNumber.Text))
Hi,
You could try to do something like this:
VB Code:
txtNumber.SelectionLength = TextBox1.Text.Length
Wkr,
sparrow1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|