|
I have a tabcontrol with 5 tabs added in order. I add the event handler for selectedindexchanged. For some reason the order inside the tabcontrol gets shuffled. Is this suppose to happen?
source code below.
To induce the bug. Click on tabpage 5 first then click on tabpage 3. Clicking on tabpage 5 diplays expected results both using index and enumeration. Upon clicking on tabpage 3. Both index and enumeration changes order.
#pragma once
namespace testform { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing;
/// /// Summary for Form1 /// /// WARNING: If you change the name of this class, you will need to change the /// 'Resource File Name' property for the managed resource compiler tool /// associated with all .resx files this class depends on. Otherwise, /// the designers will not be able to interact properly with localized /// resources associated with this form. /// public __gc class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); }
protected: void Dispose(Boolean disposing) { if (disposing && components) { components->Dispose(); } __super::Dispose(disposing); } private: System::Windows::Forms::TabControl * tabControl1; private: System::Windows::Forms::TabPage * tabPage1; private: System::Windows::Forms::TabPage * tabPage2; private: System::Windows::Forms::TabPage * tabPage3; private: System::Windows::Forms::TabPage * tabPage4; private: System::Windows::Forms::TabPage * tabPage5; private: System::Windows::Forms::TabPage * tabPage6; private: System::Windows::Forms::TabPage * tabPage7; private: System::Windows::Forms::TabPage * tabPage8;
private: System::ComponentModel::IContainer * components;
private: /// /// Required designer variable. ///
/// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// void InitializeComponent(void) { this->tabControl1 = new System::Windows::Forms::TabControl(); this->tabPage1 = new System::Windows::Forms::TabPage(); this->tabPage2 = new System::Windows::Forms::TabPage(); this->tabPage3 = new System::Windows::Forms::TabPage(); this->tabPage4 = new System::Windows::Forms::TabPage(); this->tabPage5 = new System::Windows::Forms::TabPage(); this->tabControl1->SuspendLayout(); this->SuspendLayout(); // // tabControl1 // this->tabControl1->Controls->Add(this->tabPage1); this->tabControl1->Controls->Add(this->tabPage2); this->tabControl1->Controls->Add(this->tabPage3); this->tabControl1->Controls->Add(this->tabPage4); this->tabControl1->Controls->Add(this->tabPage5); this->tabControl1->Dock = System::Windows::Forms::DockStyle::Fill; this->tabControl1->Location = System::Drawing::Point(0, 0); this->tabControl1->Name = S"tabControl1"; this->tabControl1->SelectedIndex = 0; this->tabControl1->Size = System::Drawing::Size(704, 470); this->tabControl1->TabIndex = 0; this->tabControl1->SelectedIndexChanged += new System::EventHandler(this, _SelectedIndexChanged); // // tabPage1 // this->tabPage1->Location = System::Drawing::Point(4, 22); this->tabPage1->Name = S"tabPage1"; this->tabPage1->Size = System::Drawing::Size(696, 444); this->tabPage1->TabIndex = 0; this->tabPage1->Text = S"tabPage1"; // // tabPage2 // this->tabPage2->Location = System::Drawing::Point(4, 22); this->tabPage2->Name = S"tabPage2"; this->tabPage2->Size = System::Drawing::Size(192, 74); this->tabPage2->TabIndex = 1; this->tabPage2->Text = S"tabPage2"; // // tabPage3 // this->tabPage3->Location = System::Drawing::Point(4, 22); this->tabPage3->Name = S"tabPage3"; this->tabPage3->Size = System::Drawing::Size(192, 74); this->tabPage3->TabIndex = 2; this->tabPage3->Text = S"tabPage3"; // // tabPage4 // this->tabPage4->Location = System::Drawing::Point(4, 22); this->tabPage4->Name = S"tabPage4"; this->tabPage4->Size = System::Drawing::Size(192, 74); this->tabPage4->TabIndex = 3; this->tabPage4->Text = S"tabPage4"; // // tabPage5 // this->tabPage5->Location = System::Drawing::Point(4, 22); this->tabPage5->Name = S"tabPage5"; this->tabPage5->Size = System::Drawing::Size(192, 74); this->tabPage5->TabIndex = 4; this->tabPage5->Text = S"tabPage5"; // // Form1 // this->AutoScaleBaseSize = System::Drawing::Size(5, 13); this->ClientSize = System::Drawing::Size(704, 470); this->Controls->Add(this->tabControl1); this->Name = S"Form1"; this->Text = S"Form1"; this->tabControl1->ResumeLayout(false); this->ResumeLayout(false);
}
void _SelectedIndexChanged(System::Object * sender, System::EventArgs * e) { String * pOrder = S""; for (int i =0 ; i < this->tabControl1->Controls->Count;i++) pOrder = String::Concat(pOrder,S" ",(static_cast (this->tabControl1->Controls->get_Item(i)))->Text); MessageBox::Show(pOrder);
String * pOrder2 = S""; IEnumerator * pEnum = this->tabControl1->Controls->GetEnumerator(); while (pEnum->MoveNext()) pOrder2 = String::Concat(pOrder2,S" ",(static_cast (pEnum->Current)->Text)); MessageBox::Show(pOrder2);
}
}; }
| | MigrationUser 1 Tuesday, April 20, 2004 1:25 PM | Jessica,
There is a known issue with the tab control order. To insure tab order, I created a sub:
Private sub TabOrder()
tabcontrolname.control.add("tab name1..") tabcontrolname.control.add("tab name2..") tabcontrolname.control.add("tab name3..")
End sub
I called the sub in the form load event and got around the problem.
Hope it’s helped,
Snow
| | MigrationUser 1 Thursday, December 30, 2004 3:28 AM | I just came across the same problem. The solution is not to use the Controls collection of the tab control but rather use the TabPages collection. To wit,
pOrder = String::Concat(pOrder,S" ",(static_cast <TabPage *> (this->tabControl1->Controls->get_Item(i)))->Text);
becomes
pOrder = String::Concat(pOrder,S" ",(static_cast <TabPage *> (this->tabControl1->TabPages->get_Item(i)))->Text);
and
IEnumerator * pEnum = this->tabControl1->Controls->GetEnumerator();
becomes
IEnumerator * pEnum = this->tabControl1->TabPages->GetEnumerator();
The Controls collection of a tab control does contain the child pages, but they are not held in a deterministic order (i.e., the tab order you arrange in the designer). The TabPages collection does accurately reflect the order of the pages of the tab control.
- Wayne | | MigrationUser 1 Thursday, December 02, 2004 9:40 PM | I would recommend iterating through the TabPages collection instead of the Controls collection. The Controls collection is sensitive to changes in Z-Order - since the tabpage 5 is being delay created, the order of the controls collection is affected.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformstabcontrolclasstabpagestopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolcontrolcollectionclasssetchildindextopic.asp | | MigrationUser 1 Friday, December 03, 2004 3:33 AM | Jessica,
There is a known issue with the tab control order. To insure tab order, I created a sub:
Private sub TabOrder()
tabcontrolname.control.add("tab name1..") tabcontrolname.control.add("tab name2..") tabcontrolname.control.add("tab name3..")
End sub
I called the sub in the form load event and got around the problem.
Hope it’s helped,
Snow
| | MigrationUser 1 Thursday, December 30, 2004 3:28 AM | No I've done a form with tabpage control on it and have only ever used the Collection property to assign the order of the tabs. I get the same behaviour of randomly scrambled tab pages. | | DeveloperJTM Thursday, January 19, 2006 6:49 PM | Bug? Absolutley!!! I'm using VS 2003 and have had nothing but problems with tab controls. Tabs scamble in the designer or they scrambled on compliation. I've alsohad tab pages completely disappear in the designer, to where I have to re-add the tab page controls and then re-add my group boxes and grids to the tab page controls. What a major pain in the rear!! I'm looking for an alternative to using tab pages or hoping they fixed the bug in 2005. | | Hinesdev Thursday, March 23, 2006 2:36 PM |
|