Results 1 to 4 of 4

Thread: [RESOLVED] [2008] Set focus on textbox within second tab

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    36

    Resolved [RESOLVED] [2008] Set focus on textbox within second tab

    I am trying to find the code to move the focus to a text box in a "Settings" tab on a form "tabSettings".

    no such luck at this stage

    Code:
            If txtFromName.Text <> "" AndAlso txtMailTo.Text <> "" AndAlso txtSmtpServer.Text <> "" Then
                Me.chkLaunch.Visible = True
                Me.alarmtime1 = Date.Now.AddSeconds(10)
                Me.Timer1.Start()
            Else
                MsgBox("Please update settings to continue")
                Me.tabSettings.Select()
                Me.txtUserName.Select()
                Me.txtFromName.Focus()
    
            End If
    can select a textbox on the 1st page (1/2) but not the second?

    wonder if anyone can point me in the right direction?

    cheers

  2. #2
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: [2008] Set focus on textbox within second tab

    You also need to activate the tab page of the Tab control on which the text box control is located. Lets say you have a Tab Control with two tab pages and you are currently at second tab page. Now if you want to set focus to a control of first tab then first you need to activate first tab and then set the focus to the desired control.

    vb.net Code:
    1. Private Sub Button1_Click( _
    2.     ByVal sender As System.Object, _
    3.     ByVal e As System.EventArgs _
    4. ) Handles Button1.Click
    5.  
    6.     TabControl1.SelectedTab = TabControl1.TabPages(0)
    7.     TextBox1.Focus()
    8. End Sub

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Set focus on textbox within second tab

    Only 1 control can have focus at any given time... In the else block of your if statement, you try to set focus to 3 controls, so only the last one in the sequence will actually get focus.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2009
    Posts
    36

    Re: [2008] Set focus on textbox within second tab

    [Deepak Sakpal]
    Thank you very much!!
    changed the code to
    Code:
            If txtFromName.Text <> "" AndAlso txtMailTo.Text <> "" AndAlso txtSmtpServer.Text <> "" Then
                Me.chkLaunch.Visible = True
                Me.alarmtime1 = Date.Now.AddSeconds(10)
                Me.Timer1.Start()
            Else
                MsgBox("Please update settings to continue")
    
                TabControl1.SelectedTab = TabControl1.TabPages(1)
                Me.txtFromName.Focus()
    
    
            End If
    and it worked straight off the bat.

    [stanav] - was trying to set the focus in steps but it didn't work of course.

    Thanks for your help !!

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