Hello,

I am working with form having multiple tabpages. I need to set the focus on first textbox of all tabpages. I tried to declare the following when the form loads, but only txtbox1.select() is working.

Private Sub frmMaintab_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

txtbox1.select()

'First textbox under first tab page

txtbox2.select()

'First textbox under second tab page

txtbox3.select()

'First textbox under third tab page

you can do this open your project then click on first tab then click on view from menu bar then click on tab oder here you can set the tab oder of all controles placed on form

The following solution should help.

First, locate the Textbox on each Tab that you would like to have selected when changing Tabs, and add a "_X" to the end of the Textbox's Name. For example, Textbox1 would now be named Textbox1_X.

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        For Each ctl As Control In TabControl1.SelectedTab.Controls
            If TypeOf ctl Is TextBox And ctl.Name.EndsWith("_X") Then
                ctl.Select()
                Exit For
            End If
        Next
    End Sub

If you have not put the Textbox's Tag property to better use, you can always add a Tag to the Textbox that needs to be selected.
Example: TextBox1.Tag="select", and change the "If TypeOf ctl..." line of code to the following.

If TypeOf ctl Is TextBox And ctl.Tag = "select" Then
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.