Guys,

Let me explain the application


I have - Form > Main Tab Control > Main Tab Page > User Control > Sub Tab Control > Sub Tab Page > User Control > Contols/Text Box.

Form - The main form

Main Tab Control - This contains Main Tab Pages.

Main Tab Pages - Each Tap Page is a separate file. Each Main Tap Page contains a User Control which has a Sub Tab Control.

Sub Tab Control - This contains various Tab Pages [Lets say TabOne, TabTwo, TabThree]. Only the TabOne is different for each Main Tab Page.

Sub Tab Pages - Have various controls - Text Boxes, Buttons etc.

So I want a way to access Controls in the Sub Tab Pages keeping in mind what file is open[Tab Pages in the the Main Tab Control]

Lets say I have a File Save Event from the Main Menu Bar, I need only the contents of the active file to be saved. Simplest form like a webbrowser, when you save the page only the page in the active tab is saved. In my case of course I need to keep track of the Main Tab Control active tab and the Sub Tab Control Active tab.

How do I keep track of it?

In the most simplest forms

Create a Tab Control with a tab page [TP1] . Embed a another User Cntrl - Sub Tab Control in TP1. The Sub Tab Control has tap pages [STP1, STP2]. STP1 has some text boxes, other controls. Now duplicate TP1 thru an event [new files] so that there is TP1, TP2, TP3, ....Now lets say we fire an external event, how do I keep track of the values in textboxes wrt to what Main Tab Page is open.

Should I be following a different approach?

Ideas are welcome!

Hi San24,

This is not a big problem. You can always iterate through child controls in any parent Control. Like this:

Method1
Let's say i have a Windows forms and i have some contorls on it. If i want to access the controls on the form or properties of controls i can always do this.

In this case i iterate "Enabled" property of controls on form.

foreach (Control c in this.Controls)
            {
                MessageBox.Show(c.Enabled.ToString());
            }

With this in mind you can iterate through controls in parent, then check if control is enabled or whatever you have set, and then if contorl is enabled, get it's type declare anathor variable that is of this type and then iterate through its child control and check if it is enabled and so on. I hope you understand what i mean to say. Just think and use some logic you will get it.

Method2
Anathor simple method i can suggest is that.
You can store the controls reference each time they are enabled or disabled (or whatever way you have used) in the hierarchy of controls. Store the controls reference in "EnableChanged" event. And then when somebody uses that control, you will always the control that user is working on.

Work on it. If you have any problems please feel free tell me anytime.

Thanks

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.