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. Taborder for Dynamically-Created Controls

Taborder for Dynamically-Created Controls

Scheduled Pinned Locked Moved C#
help
9 Posts 4 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
    danielhasdibs
    wrote on last edited by
    #1

    My code creates textboxes based on data from a file. I need to be able to retreive the text from each dynamically-created textbox. By the way, each textbox is contained in a splitcontainer control (spc_Questions). Here is the code that creates each textbox: for (cntr = 0; cntr <; NumQ; cntr++) { input = sr.ReadLine(); newTextBox = new System.Windows.Forms.TextBox(); newTextBox.Size = new Size(25, newTextBox.Size.Height); newTextBox.MaxLength = 1; newTextBox.CharacterCasing = CharacterCasing.Upper; newTextBox.TabStop = true; newTextBox.TabIndex = cntr; newTextBox.Location = new Point(spc_Questions.Panel1.Right - newTextBox.Size.Width - 10, vHeight); newTextBox.Tag = cntr.ToString(); newTextBox.Show(); spc_Questions.Panel1.Controls.Add(newTextBox); } Any help would be appreciated. :)

    J T L 3 Replies Last reply
    0
    • D danielhasdibs

      My code creates textboxes based on data from a file. I need to be able to retreive the text from each dynamically-created textbox. By the way, each textbox is contained in a splitcontainer control (spc_Questions). Here is the code that creates each textbox: for (cntr = 0; cntr <; NumQ; cntr++) { input = sr.ReadLine(); newTextBox = new System.Windows.Forms.TextBox(); newTextBox.Size = new Size(25, newTextBox.Size.Height); newTextBox.MaxLength = 1; newTextBox.CharacterCasing = CharacterCasing.Upper; newTextBox.TabStop = true; newTextBox.TabIndex = cntr; newTextBox.Location = new Point(spc_Questions.Panel1.Right - newTextBox.Size.Width - 10, vHeight); newTextBox.Tag = cntr.ToString(); newTextBox.Show(); spc_Questions.Panel1.Controls.Add(newTextBox); } Any help would be appreciated. :)

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      danielhasdibs wrote:

      Any help would be appreciated.

      Im sure it would be, but you forgot to ask a question! :confused:

      D 1 Reply Last reply
      0
      • J J4amieC

        danielhasdibs wrote:

        Any help would be appreciated.

        Im sure it would be, but you forgot to ask a question! :confused:

        D Offline
        D Offline
        danielhasdibs
        wrote on last edited by
        #3

        Question = How?

        1 Reply Last reply
        0
        • D danielhasdibs

          My code creates textboxes based on data from a file. I need to be able to retreive the text from each dynamically-created textbox. By the way, each textbox is contained in a splitcontainer control (spc_Questions). Here is the code that creates each textbox: for (cntr = 0; cntr <; NumQ; cntr++) { input = sr.ReadLine(); newTextBox = new System.Windows.Forms.TextBox(); newTextBox.Size = new Size(25, newTextBox.Size.Height); newTextBox.MaxLength = 1; newTextBox.CharacterCasing = CharacterCasing.Upper; newTextBox.TabStop = true; newTextBox.TabIndex = cntr; newTextBox.Location = new Point(spc_Questions.Panel1.Right - newTextBox.Size.Width - 10, vHeight); newTextBox.Tag = cntr.ToString(); newTextBox.Show(); spc_Questions.Panel1.Controls.Add(newTextBox); } Any help would be appreciated. :)

          T Offline
          T Offline
          teejayem
          wrote on last edited by
          #4

          you need to set the TabIndex Property

          Don't be overcome by evil, but overcome evil with good

          D 1 Reply Last reply
          0
          • T teejayem

            you need to set the TabIndex Property

            Don't be overcome by evil, but overcome evil with good

            D Offline
            D Offline
            danielhasdibs
            wrote on last edited by
            #5

            It's set after I create the text box. newTextBox.TabIndex = cntr; I've been trying to use the SelectNextControl() method to get to each textbox control, but it keeps selecting the splitcontainer instead of the textboxes.

            T 1 Reply Last reply
            0
            • D danielhasdibs

              It's set after I create the text box. newTextBox.TabIndex = cntr; I've been trying to use the SelectNextControl() method to get to each textbox control, but it keeps selecting the splitcontainer instead of the textboxes.

              T Offline
              T Offline
              teejayem
              wrote on last edited by
              #6

              what are you using passing in the first parameter in SelectNextControl()?

              Don't be overcome by evil, but overcome evil with good

              D 1 Reply Last reply
              0
              • D danielhasdibs

                My code creates textboxes based on data from a file. I need to be able to retreive the text from each dynamically-created textbox. By the way, each textbox is contained in a splitcontainer control (spc_Questions). Here is the code that creates each textbox: for (cntr = 0; cntr <; NumQ; cntr++) { input = sr.ReadLine(); newTextBox = new System.Windows.Forms.TextBox(); newTextBox.Size = new Size(25, newTextBox.Size.Height); newTextBox.MaxLength = 1; newTextBox.CharacterCasing = CharacterCasing.Upper; newTextBox.TabStop = true; newTextBox.TabIndex = cntr; newTextBox.Location = new Point(spc_Questions.Panel1.Right - newTextBox.Size.Width - 10, vHeight); newTextBox.Tag = cntr.ToString(); newTextBox.Show(); spc_Questions.Panel1.Controls.Add(newTextBox); } Any help would be appreciated. :)

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Please Try this Code , it's about buttons Control , but it think you will understand my idea ...... public partial class Form1 : Form { public Button sb; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { for (int x = 0; x < 10; x++) { sb = new Button(); sb.Size = new Size(17, 17); sb.Location = new Point(x * 17, 10); sb.Tag = (x).ToString(); sb.Visible = true; sb.Click += new EventHandler(sb_Click); Controls.Add(sb); } this.Size = new Size(176, (12 * 17) + 7); } private void sb_Click(object sender, System.EventArgs e) { Button sb = sender as Button; this.Text = sb.Tag.ToString(); }

                I know nothing , I know nothing ...

                D 1 Reply Last reply
                0
                • T teejayem

                  what are you using passing in the first parameter in SelectNextControl()?

                  Don't be overcome by evil, but overcome evil with good

                  D Offline
                  D Offline
                  danielhasdibs
                  wrote on last edited by
                  #8

                  Here's a sample of the SelectNextControl() method I used. string[] textFromControl = new string[10]; Control nextControl = new Control(); spc_Questions.Focus(); for (cntr = 0; cntr <; NumControls; cntr++) { this.SelectNextControl(nextControl, true, true, true, true); nextControl = this.ActiveControl; nextControl.Focus(); textFromControl[cntr] = nextControl.Text; }

                  1 Reply Last reply
                  0
                  • L Lost User

                    Please Try this Code , it's about buttons Control , but it think you will understand my idea ...... public partial class Form1 : Form { public Button sb; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { for (int x = 0; x < 10; x++) { sb = new Button(); sb.Size = new Size(17, 17); sb.Location = new Point(x * 17, 10); sb.Tag = (x).ToString(); sb.Visible = true; sb.Click += new EventHandler(sb_Click); Controls.Add(sb); } this.Size = new Size(176, (12 * 17) + 7); } private void sb_Click(object sender, System.EventArgs e) { Button sb = sender as Button; this.Text = sb.Tag.ToString(); }

                    I know nothing , I know nothing ...

                    D Offline
                    D Offline
                    danielhasdibs
                    wrote on last edited by
                    #9

                    Thank you! Below is how I implemented it for anyone who needs it (this is in a splitcontainer -- spc_Questions): for (cntr = 0; cntr <; NumControls; cntr++) { newTextBox = new System.Windows.Forms.TextBox(); newTextBox.Size = new Size(25, newTextBox.Size.Height); newTextBox.Location = new Point(spc_Questions.Panel1.Right - newTextBox.Size.Width - 10, cntr * setHeight); // Tag needed to identify controls newTextBox.Tag = cntr.ToString(); newTextBox.TextChanged += new EventHandler(newTextBox_TextChanged); newTextBox.Show(); spc_Questions.Panel1.Controls.Add(newTextBox); } void newTextBox_TextChanged(object sender, EventArgs e) { TextBox Text = sender as TextBox; ControlTexts[int.Parse(Text.Tag.ToString())] = Text.Text; } Thank you, again!

                    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