Share via


List of controls on a tabPage

Question

Friday, March 26, 2010 10:21 AM

How do I retrieve list of all controls on my tabPage?

All replies (3)

Friday, March 26, 2010 12:09 PM âś…Answered

Hi RokoLAB

You could iterate over your tab pages in the tab control in the following manner. Assume your tab control name is tabControl1 .

private void button1_Click(object sender, EventArgs e)
{
    // Iterates throught all the tabs in the tab control.
    foreach (Control tab in tabControl1.Controls)
    {
        TabPage tabPage = (TabPage)tab;
        
        // Iterates through all the controls (i.e. textboxes, buttons, labels, etc.) in the tab page.
        foreach (Control control in tabPage.Controls)
        {
            MessageBox.Show(control.GetType().ToString());
        }
    }
}

Hope this helps you.

 

Best Regards,

Praneeth


Friday, March 26, 2010 10:40 AM

You can get the details of your controls :

 

for (int intIndex = 0; intIndex < this.Controls.Count; intIndex++)

            {

                MessageBox.Show("Control # " + intIndex.ToString() + " has the name " + this.Controls[intIndex].Name);

            }

 

 

Hope this will help

Make it as answer if so.. :)

 

http://www.thurupathan.spaces.com/


Friday, March 26, 2010 12:23 PM

           ///Get the text from all label control of tabpage 1
            foreach (Control c in tabControl1.TabPages[0].Controls)
            {
                if (c is Label)
                {
                    MessageBox.Show(((Label)c).Text);
                }
            }

            ///Get the count of controls in tab page 1
            int count = tabControl1.TabPages[0].Controls.Count;
Thanks,
A.m.a.L
Dot Net Goodies
Don't hate the hacker, hate the code