title: how to dynamically add rows and columns in table layout panel
body: <p>I am working on windows application in C#.I have created one windows form,in that I have added one table panel control.In database I am having one table which is having 4 columns like book name,book image,book category and book sub category.Now I am having 10 records in a table.</p>
  
  <p>I want to show all those data in table panel.I have tried following code.But I am not getting proper output.I have to add one picture box control and three label control i.e I have to create 4 columns ,so Column 1 will have picture box and other three columns have one label in each.The code I try gives me the output,but it is not proper.It shows picture box image in all 4 columns,then labels.</p>
  
  <p>But I want to show the output like,each column should contain unique data.</p>
  
  <p>Code:</p>
  
  <pre><code>public void DynamicGenerateTable(int columnCount, int rowCount)
      {
          tableLayoutPanel1.Controls.Clear();
          //Clear out the existing row and column styles
          tableLayoutPanel1.ColumnStyles.Clear();
          tableLayoutPanel1.RowStyles.Clear();
  
          //Assign table no of rows and column
          tableLayoutPanel1.ColumnCount = columnCount;
          tableLayoutPanel1.RowCount = rowCount;
          WiCommonFunction.LoadCommonSettings();
          ShowInformation show = new ShowInformation();
          //ds = show.ShowBookImage();
          ds1 = show.ShowBookCategory();
          DataTable dt1 = ds1.Tables[0];
  
          for (int i = 0; i &lt; columnCount; i++)
          {
              tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
  
              for (int j = 0; j &lt; rowCount; j++)
              {
                  if (i == 0)
                  {
                      //defining the size of cell
                      tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                  }
                  PictureBox picture = new PictureBox();
                  picture.Size = new Size(220, 180);
                  picture.SizeMode = PictureBoxSizeMode.StretchImage;
                  Byte[] byteImage = (Byte[])(dt1.Rows[j]["BookImage"]);
                  MemoryStream ms = new MemoryStream(byteImage);
                  picture.Image = Image.FromStream(ms);
  
                  Label lblCategory = new Label();
                  lblCategory.Text = dt1.Rows[j]["CategoryName"].ToString();
  
                  Label lblSubCategory = new Label();
                  lblCategory.Text = dt1.Rows[j]["SubCategoryName"].ToString();
  
                  Label lblBook = new Label();
                  lblBook.Text = dt1.Rows[j]["BookName"].ToString();
                  tableLayoutPanel1.Controls.Add(picture,i,j);
                  tableLayoutPanel1.Controls.Add(lblCategory, i, j);
                  tableLayoutPanel1.Controls.Add(lblSubCategory, i, j);
                  tableLayoutPanel1.Controls.Add(lblBook, i, j);
              }
          }
      }
  </code></pre>
  
  <p>Please suggest me any solution.Thanks in advance.</p>