Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How do we set the TabIndex at runtime? I have WinForm on which I am creating PictureBoxes at runtime. On the form, first the TableLayout is created, each cell in TableLayout contains a Panel, each Panel contains a Picture Box and a Label.

I am using this code to create the above Table Layout.
C#
for (int col = 0; col <= tableLayoutPanel1.ColumnCount - 1; col++)
      {
        for (int rows = 0; rows <= tableLayoutPanel1.RowCount - 1; rows++)
        {
          tableLayoutPanel1.Controls.Clear();
          tableLayoutPanel1.RowCount = int.Parse(rowsTextBox.Text);
          tableLayoutPanel1.ColumnCount = int.Parse(columnsTextBox.Text);
          Panel p = new Panel();
          TextBox tb = new TextBox();
          PictureBox picb = new PictureBox();
          picb.BackColor = Color.White;
          p.Controls.Add(tb);
          p.Controls.Add(picb);
          picb.Location = new Point(0, tb.Top + 20);          
          picb.MouseLeave += PicbLSB;
          tableLayoutPanel1.Controls.Add(p, col, rows);          
        }
      }



I wanted to set the TabIndex property of the PictureBoxes starting 0 from the first PictureBox created and 'last' for the last PictureBox created.
Thanks
Posted
Comments
Abhishek Sur 10-Oct-10 10:17am    
doesnt the TabStop works for you ?
OriginalGriff 10-Oct-10 11:15am    
"In other case, if I would have use a 'Panel' which has a TabIndex property. I wanted to set the TabIndex property of the Panels starting 0 from the first Panel created in the above code and 'last' for the last Panel created. - optimus_prime1 26 mins ago"
So do it? What is the problem?

1 solution

Why?
Since a picture box cannot be tabbed to, the TabIndex is irrelevent - see MSDN PictureBox.TabIndex Property[^]
It is even masked so you can't set it at design time!
 
Share this answer
 
Comments
optimus_prime1 10-Oct-10 10:46am    
In other case, if I would have use a 'Panel' which has a TabIndex property. I wanted to set the TabIndex property of the Panels starting 0 from the first Panel created in the above code and 'last' for the last Panel created.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900