0
votes

Form Structure:

a) On form1 there are 4 checkboxes and form2 has a tabcontrol1 with 4 tabpages.

b) Each checkbox on form1 is linked with a tabpage on form2.

c) Each tabpage has fixed controls.

I am trying to achieve following with above structure,

a) With a "OK" button on form1, I want to show the user only those tabpages for which checkboxes are checked.

b) With "Cancel" button on form2 I want to restore all the tabpages with controls.


I tried following but it is not working as desired and adds blank tabpages.

Code under "OK" button on form1:

If CheckBox1.Checked Then
   Form2.TabControl1.TabPages.Remove(Form2.TabControl1.TabPages(1))
   Form2.TabControl1.TabPages.Remove(Form2.TabControl1.TabPages(2))
   Form2.TabControl1.TabPages.Remove(Form2.TabControl1.TabPages(3))
End If
If CheckBox2.Checked Then
   Form2.TabControl1.TabPages.Remove(Form2.TabControl1.TabPages(0))
   Form2.TabControl1.TabPages.Remove(Form2.TabControl1.TabPages(2))
   Form2.TabControl1.TabPages.Remove(Form2.TabControl1.TabPages(3))
End If
If CheckBox3.Checked Then
   Form2.TabControl1.TabPages.Remove(Form2.TabControl1.TabPages(0))
   Form2.TabControl1.TabPages.Remove(Form2.TabControl1.TabPages(1))
   Form2.TabControl1.TabPages.Remove(Form2.TabControl1.TabPages(3))
End If
If CheckBox4.Checked Then
   Form2.TabControl1.TabPages.Remove(Form2.TabControl1.TabPages(0))
   Form2.TabControl1.TabPages.Remove(Form2.TabControl1.TabPages(1))
   Form2.TabControl1.TabPages.Remove(Form2.TabControl1.TabPages(2))
End If
Me.Hide()
Form2.Show()

Code under "Cancel" button on Form2:

Me.Refresh()
TabControl1.TabPages.Insert(1, TabPage2)
TabControl1.TabPages.Insert(2, TabPage3)
Me.Hide()
Form1.Show()
1

1 Answers

0
votes

Instead of Removing the tabpages, use Hide() and Show() function of the TabPage.