Hello everyone!

I'm new here, and I'm trying to find the awnser to my question already for a few hours, I tried to search didn't find anything at all...

So now I'm here.

I'm trying to make an application where you can search trough a database and then return the values. At the moment is what I am trying to do is changing my mainTab Control by a child form (Main form opens Search form, and the Search form has to be able to change the mainTab Control on the Main form)

Does anyone know how you can do this?

At the moment I have this:

Employee ret = new Employee();
            Main mn = new Main();
            ret.EmpID = empID;
            ret.TopLevel = false;
            ret.Parent = this;
            if (Int32.Parse(ConfigurationManager.AppSettings["useTabs"]) == 1)
            {
                ret.Dock = DockStyle.Fill;
                ret.FormBorderStyle = FormBorderStyle.None;
                TabPage newTab = new TabPage("Tesfghfghfghfghfhgfghfghfghfght");
                newTab.Controls.Add(ret);
                mn.mainTab.TabPages.Add(newTab);
                mn.mainTab.SelectedTab = mn.mainTab.TabPages[mn.mainTab.TabPages.Count - 1];
                mn.Refresh();
                this.Parent.Controls.Add(ret);
            }
            else
            {
                mn.mainPanel.Controls.Add(ret);
            }
            ret.Show();

But that don't think that is working because I'm creating a new Main, while it should change on the Main which is already there.

Kind Regards,

Of course the main form is created again.
That is exactly what you are doing on line 2.

You need to pass a reference to your main form to the search form.
Try looking at this post.
Which is also found in the Similar Threads for this thread!

It's bad design for one form to manipulate the controls on another form. Your second form should send a message (event) to the first form so it can manipulate its own controls.

commented: How true. +10
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.