views:

15

answers:

0

Hi,

I am creating a TableLayout in which the rows and columns are set by the user at runtime.

There initial controls on the form are rowsTextBox, columnsTextBox, button1 and tableLayoutPanel1.

I modified some of the code from my initial program. Here's the old code.

private void button1_Click(object sender, EventArgs e)
 {
  tableLayoutPanel1.RowCount = int.Parse(rowsTextBox.Text);
  tableLayoutPanel1.ColumnCount = int.Parse(columnsTextBox.Text);

  for (int col = 0; col < tableLayoutPanel1.ColumnCount; col++)
  {
  for (int rows = 0; rows < tableLayoutPanel1.RowCount; rows++)
  {
   Panel p = new Panel();
   TextBox tb = new TextBox();
   Button btn = new Button();
   p.Controls.Add(tb);
   p.Controls.Add(btn);
   btn.Location = new Point(0, tb.Top + 20);
   tableLayoutPanel1.Controls.Add(p, col, rows);
  }
  }

Here's the new code in the same button click event. Just some additions , the basic code remains the same but I dont know the number of rows and columns being formed are not correct. (try 5 x5 or 6. x6 etc. greater than 3x3 )

output.Person.Clear();
        output.Row = int.Parse(rowsTextBox.Text);
        output.Column = int.Parse(columnsTextBox.Text);
        tableLayoutPanel1.Controls.Clear();
        tableLayoutPanel1.RowCount = int.Parse(rowsTextBox.Text);
        tableLayoutPanel1.ColumnCount = int.Parse(columnsTextBox.Text);
        tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;
        for (int col = 0; col <= tableLayoutPanel1.ColumnCount - 1; col++)
        {
          for (int rows = 0; rows <= tableLayoutPanel1.RowCount - 1; rows++)
          {
            Panel p = new Panel();
            PictureBox picb = new PictureBox();
            Label lb = new Label();
            p.Controls.Add(lb);
            p.Controls.Add(picb);
            //Set the label properties            
            lb.BackColor = Color.White;
            lb.Size = new Size(88, 15);
            lb.Location = new Point(panel1.Left + 1, panel1.Top + 1);
            //Set the picture box properties            
            picb.Location=new Point(0,lb.Top + 20);
            picb.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
            picb.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
            picb.BackColor = Color.White;
            picb.Dock = DockStyle.Fill;                                              
            tableLayoutPanel1.Controls.Add(p, col, rows);
            p.Dock = DockStyle.Fill;            
            picb.MouseClick += pb_Click;            
            LayoutItem item = new LayoutItem()
            {
              //This assignment is new in Visual studio 2008
              ItemLabel = lb,
              ItemPcitureBox = picb,
              pnlcolor=p
            };
            m_items.Add(item);            
            Customer c = new Customer();
            c.Index = col * tableLayoutPanel1.RowCount + rows

If required, here is the sample on skydrive in which I tried the same. Aren't both of them same

http://cid-7cfad5624f27df6f.office.live.com/self.aspx/.Public/Sample.zip?wa=wsignin1.0&amp;sa=477673719

I tried many things but still lingering with the problem. However, I noticed that the TableLayoutPanel on the Form inside a PlaceHolder i.e. Panel and set the TableLayoutPanel dockstyle to Fill so that the TableLayoutPanel covers the whole form. Panel is anchored to Top, Left, Bottom, Right. I think this panel has to do something with the problem.

The rows adjust themselves according to the size of the Form and not to the size of the Panel (which in this case is less than the size of the form).

and here is the sample(Skydrive) in which the Panel isn't used and the program is working fine. [http://]cid-7cfad5624f27df6f.office.live.com/self.aspx/.Public/WindowsFormsApplication6.zip

In my case, it was essential to use the Panel since I had to Fill the TableLayout on the Form.

Also, I may be wrong since I tried to remove the Panel from the problematic program but the cells still weren't becoming equal.

Please HELP!!!