[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
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:
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles Button1.Click
TabControl1.SelectedTab = TabControl1.TabPages(0)
TextBox1.Focus()
End Sub
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.
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 !!