Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. TabPages controls created on the fly [modified]

TabPages controls created on the fly [modified]

Scheduled Pinned Locked Moved C#
helptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dave kelly
    wrote on last edited by
    #1

    I am creating TabPages dynamically, adding a few textboxes, buttons etc. I can't figure out though how to access these controls. I tried:

    foreach (TabPage tp in tabControl1.TabPages)
    {
    foreach (Control c in tp)
    {
    if (c is CheckBox)
    {
    if (c.Enabled == true)
    MessageBox.Show ("Enabled");
    }
    }
    }

    but get the error that TabPage does not contain a definition for GetEnumerator(). As the controls are created dynamically, I can't access them by name in the code. Any ideas on how to access these controls? -- modified at 4:06 Thursday 11th October, 2007

    R S 3 Replies Last reply
    0
    • D dave kelly

      I am creating TabPages dynamically, adding a few textboxes, buttons etc. I can't figure out though how to access these controls. I tried:

      foreach (TabPage tp in tabControl1.TabPages)
      {
      foreach (Control c in tp)
      {
      if (c is CheckBox)
      {
      if (c.Enabled == true)
      MessageBox.Show ("Enabled");
      }
      }
      }

      but get the error that TabPage does not contain a definition for GetEnumerator(). As the controls are created dynamically, I can't access them by name in the code. Any ideas on how to access these controls? -- modified at 4:06 Thursday 11th October, 2007

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      That sounds odd, I would have thought what you're doing is fine. Try changing the outer loop from a foreach to a standard for loop. The implication is that the TabPages collection does not implement IEnumerable.

      Regards, Rob Philpott.

      1 Reply Last reply
      0
      • D dave kelly

        I am creating TabPages dynamically, adding a few textboxes, buttons etc. I can't figure out though how to access these controls. I tried:

        foreach (TabPage tp in tabControl1.TabPages)
        {
        foreach (Control c in tp)
        {
        if (c is CheckBox)
        {
        if (c.Enabled == true)
        MessageBox.Show ("Enabled");
        }
        }
        }

        but get the error that TabPage does not contain a definition for GetEnumerator(). As the controls are created dynamically, I can't access them by name in the code. Any ideas on how to access these controls? -- modified at 4:06 Thursday 11th October, 2007

        S Offline
        S Offline
        Spunky Coder
        wrote on last edited by
        #3

        we can do like the following one... foreach (TabPage tp in tabControl1.TabPages) { for (int i = 0; i < tp.Controls.Count;i++) { if (tp.Controls[0] is CheckBox) { if(((CheckBox)(tp.Controls[0])).Enabled) MessageBox.Show ("Enabled"); } } }

        Koushik

        1 Reply Last reply
        0
        • D dave kelly

          I am creating TabPages dynamically, adding a few textboxes, buttons etc. I can't figure out though how to access these controls. I tried:

          foreach (TabPage tp in tabControl1.TabPages)
          {
          foreach (Control c in tp)
          {
          if (c is CheckBox)
          {
          if (c.Enabled == true)
          MessageBox.Show ("Enabled");
          }
          }
          }

          but get the error that TabPage does not contain a definition for GetEnumerator(). As the controls are created dynamically, I can't access them by name in the code. Any ideas on how to access these controls? -- modified at 4:06 Thursday 11th October, 2007

          R Offline
          R Offline
          Rob Philpott
          wrote on last edited by
          #4

          oh yes, just spotted it. its this : foreach (Control c in tp) should be; foreach (Control c in tp.Controls) or something like that. Can't remember what the collection is called.

          Regards, Rob Philpott.

          D 1 Reply Last reply
          0
          • R Rob Philpott

            oh yes, just spotted it. its this : foreach (Control c in tp) should be; foreach (Control c in tp.Controls) or something like that. Can't remember what the collection is called.

            Regards, Rob Philpott.

            D Offline
            D Offline
            dave kelly
            wrote on last edited by
            #5

            Thanks guys, the

            foreach (Control c in tp.Controls)

            was what I needed.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups