Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with TabControl

Status
Not open for further replies.

ChewDoggie

Programmer
Mar 14, 2005
604
US
Hello,

Does anyone know how to programmatically set WHICH TAB is selected when a form that contains a TabControl is loaded?

I have two tabs, tbPersonalInfo (the first tab) and tbContactInfo (the second tab). I'd like to have the tbContactInfo tab selected when the form opens.

I've tried:

Code:
        private void TabbedDetails_Activated(object sender, EventArgs e)
            {
            switch (WhichTab)
                {
                case "personal":
                    this.tbPersonalInfo.Select();
                    break;
                case "contact":
                    tbContactInfo.Select();
                    break;
                }
            }

AND ALSO:

Code:
        private void TabbedDetails_Activated(object sender, EventArgs e)
            {
            switch (WhichTab)
                {
                case "personal":
                    this.tbPersonalInfo.Show();
                    break;
                case "contact":
                    tbContactInfo.Show();
                    break;
                }
            }

And neither method selects the desired tab.

Thanks !

Chew

10% of your life is what happens to you. 90% of your life is how you deal with it.
 
FYI...I solved this problem with this code in the tabbed form:

Code:
        public int WhichTab;

        private void TabbedDetails_Activated(object sender, EventArgs e)
            {
            switch (WhichTab)
                {
                case 0:
                    LoadPersonalInfo();
                    break;
                case 1:
                    LoadContactInfo();
                    break;
                case 2:
                    LoadDepartmentInfo();
                    break;
                case 3:
                    LoadStatusInfo();
                    break;
                case 4:
                    LoadFMLAInfo();
                    break;
                case 5:
                    LoadMilitaryInfo();
                    break;
                }
            this.tbInformation.SelectedIndex = WhichTab;
            LoadingForm = false;
            }

..and this code on the MdiParent Form (Context Menu Strip -- cmsAssociates):
Code:
        private void cmsAssociates_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
            {
            int WhichTab = 0;
            if (frmAssociates.Visible && frmAssociates.WindowState != FormWindowState.Minimized)
                {
                frmAssociates.WindowState = FormWindowState.Minimized;
                }
            frmDetails = new TabbedDetails();
            switch (e.ClickedItem.ToString())
                {
                case "Contact":
                    WhichTab = 1;
                    break;
                case "Department":
                    WhichTab = 2;
                    break;
                case "Status":
                    WhichTab = 3;
                    break;
                case "FMLA":
                    WhichTab = 4;
                    break;
                case "Military":
                    WhichTab = 5;
                    break;
                }
            frmDetails.WhichTab = WhichTab;
            frmDetails.MdiParent = this;
            frmDetails.Show();
            frmDetails.FormClosing += new FormClosingEventHandler(onFormClosing);
            scmnuNew.Enabled = false;
            }
Chew


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
Did you look at something like this:
Code:
		private void Form1_Load(object sender, System.EventArgs e)
		{
			tabControl1.SelectedTab = tabControl1.TabPages[1];
		}

That should select the second tab or did I miss something?

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
I'm was trying to set the tab in the Child Form from the Parent Form.

Chew

10% of your life is what happens to you. 90% of your life is how you deal with it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top