Results 1 to 4 of 4

Thread: [RESOLVED] VB2005 Select value in textbox on formload

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Resolved [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:
    1. Me.txtNumber.Text = 1
    2. Me.txtNumber.Focus()
    3. Me.txtNumber.Select(0, Len(txtNumber.Text))

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    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.

  4. #4
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    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:
    1. Me.txtNumber.Text = 1
    2. Me.txtNumber.Focus()
    3. Me.txtNumber.Select(0, Len(txtNumber.Text))
    Hi,

    You could try to do something like this:

    VB Code:
    1. txtNumber.SelectionLength = TextBox1.Text.Length

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

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