[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))
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.
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.
Re: [RESOLVED] VB2005 Select value in textbox on formload
Quote:
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