0

I created one xtratab control.I created two tab pages in that named entry and reports. I created one more windows form and in that I created menu. in that menu I created two option bars name entry and report. when I click on entry in menu than that xtra tab page should come with entry tab selected. If I click on report in menu than that xtratab report page should open.

I searched in net but they told how to specify tab page in form while form is loading like Tab.SelectedTabPage = xtraTabPage2; But this is not suitable for my condition.

vijay
  • 35
  • 10
  • What do you mean by "But this is not suitable for my condition." ? Can you clarify what are you trying to accomplish in more details? – Luthfi Nov 03 '18 at 15:29
  • @FrustratedEveryday I will explain more clearly. I created one xtratab control.I created two tab pages in that named entry and reports. I created one more windows form and in that I created menu. in that menu I created two option bars name entry and report. when I click on entry in menu than that xtra tab page should come with entry tab selected. If I click on report in menu than that xtratab report page should open. – vijay Nov 04 '18 at 08:01
  • So do you want to change the selected tab through another form? You may want to consider to update your question :) – Luthfi Nov 04 '18 at 08:04
  • @ FrustratedEveryday, I updated My question like what you told – vijay Nov 04 '18 at 08:11

1 Answers1

2

The easiest way to achive your goal is to set your XtraTabControl's and it's tab member modifier to public. Then at your Another Form's constructor, pass your First Form as a parameter.

Your AnotherForm should look like this:

private readonly Form1 _form1;

public AnotherForm(Form1 form1)
{
    _form1 = form1;
    InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
    _form1.xtraTabControl1.SelectedTabPage = _form1.xtraTabPage1;
}

private void button2_Click(object sender, EventArgs e)
{
    _form1.xtraTabControl1.SelectedTabPage = _form1.xtraTabPage2;
}

Now call AnotherForm from your main form: new AnotherForm(this).ShowDialog();

If you don't want to set xtraTabPage's modifier to public you can simply use SelectedTabPageIndex which is integer type.

enter image description here

Luthfi
  • 478
  • 1
  • 3
  • 16
  • what I have to mention in Programs.cs – vijay Nov 04 '18 at 09:11
  • error coming in program.cs that "there is no argument given that corresponds to the required formal parameter form1 of 'Form2.Form2(Form1)'. I created Form1 and in that created xtratab control and created two tab pages.all modifiers I changed to public as you told. I created Form2 and added the code what you wrote above. – vijay Nov 04 '18 at 09:43
  • I want to run Form2. In From2 according to the selected option only I have to run Form1 and open selected tab page. How to achieve that – vijay Nov 04 '18 at 10:01
  • OK. I added like what you told. It is opening Form1 and Form2. If I want to run Form2 Directly from program.cs what I have to do. – vijay Nov 04 '18 at 10:10
  • @vijay I was answering related to this question. You should open a new question for that. – Luthfi Nov 04 '18 at 10:14
  • @ FrustratedEveryday, I asked that question only see above my question. But what you gave solution is for me some what helpful. – vijay Nov 04 '18 at 10:22
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/183075/discussion-between-vijay-and-frustratedeveryday). – vijay Nov 04 '18 at 11:28