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. Add controls to a tab page at run-time

Add controls to a tab page at run-time

Scheduled Pinned Locked Moved C#
designhelp
7 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.
  • C Offline
    C Offline
    CodingLover
    wrote on last edited by
    #1

    Hi all, I want to add a ListBox into a tab page at run time, not design time. Can someone give me a clue. Thanks

    I appreciate your help all the time... CodingLover :)

    M 1 Reply Last reply
    0
    • C CodingLover

      Hi all, I want to add a ListBox into a tab page at run time, not design time. Can someone give me a clue. Thanks

      I appreciate your help all the time... CodingLover :)

      M Offline
      M Offline
      michael cohen
      wrote on last edited by
      #2

      this is something i made a few days ago... private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { RefreshList(); switch (tabControl1.SelectedIndex) { case 0: tabPage1.Controls.Add(groupBox2); tabPage1.Controls.Add(groupBox1); break; case 1: tabPage2.Controls.Add(groupBox2); tabPage2.Controls.Add(groupBox1); break; case 2: tabPage3.Controls.Add(groupBox2); tabPage3.Controls.Add(groupBox1); break; default: break; } }

      C 1 Reply Last reply
      0
      • M michael cohen

        this is something i made a few days ago... private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { RefreshList(); switch (tabControl1.SelectedIndex) { case 0: tabPage1.Controls.Add(groupBox2); tabPage1.Controls.Add(groupBox1); break; case 1: tabPage2.Controls.Add(groupBox2); tabPage2.Controls.Add(groupBox1); break; case 2: tabPage3.Controls.Add(groupBox2); tabPage3.Controls.Add(groupBox1); break; default: break; } }

        C Offline
        C Offline
        CodingLover
        wrote on last edited by
        #3

        Mainly what I want to do is this. In my tab control added three tabs. Initially added ListBox to the first tab. Next time, if the tab page 1 have a list box I want to add to the next tab page.

        I appreciate your help all the time... CodingLover :)

        M 1 Reply Last reply
        0
        • C CodingLover

          Mainly what I want to do is this. In my tab control added three tabs. Initially added ListBox to the first tab. Next time, if the tab page 1 have a list box I want to add to the next tab page.

          I appreciate your help all the time... CodingLover :)

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Michael gave you the answers, use selected tab to identify the page, check if the control has been added to the pages control collection if it is missing then add it to the collection. All the commands are in Michaels example, you can't expect someone to write it to match your somewhat twisted logic.

          Never underestimate the power of human stupidity RAH

          C 1 Reply Last reply
          0
          • M Mycroft Holmes

            Michael gave you the answers, use selected tab to identify the page, check if the control has been added to the pages control collection if it is missing then add it to the collection. All the commands are in Michaels example, you can't expect someone to write it to match your somewhat twisted logic.

            Never underestimate the power of human stupidity RAH

            C Offline
            C Offline
            CodingLover
            wrote on last edited by
            #5

            I'm not expecting any code pal. :) I just wonder how to find a page has a control or not. In other words, how to find something is contain in a specific tab page.

            I appreciate your help all the time... CodingLover :)

            M 1 Reply Last reply
            0
            • C CodingLover

              I'm not expecting any code pal. :) I just wonder how to find a page has a control or not. In other words, how to find something is contain in a specific tab page.

              I appreciate your help all the time... CodingLover :)

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              check the tab pages control collection

              Never underestimate the power of human stupidity RAH

              M 1 Reply Last reply
              0
              • M Mycroft Holmes

                check the tab pages control collection

                Never underestimate the power of human stupidity RAH

                M Offline
                M Offline
                michael cohen
                wrote on last edited by
                #7

                may be this code could help you... // use this one to find a control on you tabcontrol tabControl1.Controls.Find("Control"); //use this one to see if there any controls on the tab page tabControl1.Controls.Count Or //getting the number of tab pages... tabControl1.TabCount

                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