Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4270676
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:20:19+00:00 2026-05-21T07:20:19+00:00

I have a TableLayoutPanel control that is initially empty – 0 rows and 0

  • 0

I have a TableLayoutPanel control that is initially empty – 0 rows and 0 cols. I want to form it, and fill it with some controls from code, and it works, but i have some nasty problem – when i add controls to TableLayoutPanel using code, cols and rows are not the same size (although all added controls ARE the same size, and docked to fill cells in TableLayoutPanel container). Basically first row takes about 50% of height, and two next rows take 25% each.

code i have tried looks like this:

//Reseting table:
tableLayoutPanel1.RowCount = 1;
tableLayoutPanel1.ColumnCount = 1;

//Size of one side of matrix:
int oneSide=(int)Math.Sqrt(mat.Matrix.Length);

tableLayoutPanel1.RowCount = oneSide;
tableLayoutPanel1.ColumnCount = oneSide;

tableLayoutPanel1.RowStyles.Clear();
tableLayoutPanel1.ColumnStyles.Clear();
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 100 / oneSide));
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100 / oneSide));

//Matrix is an array of controls, mat is some class
tableLayoutPanel1.Controls.AddRange(mat.Matrix);

Above code isn’t doing the job…How to add somtrols from code, and make all cells the same size?
P.S. i HAVE to add controls from code, creating rows and cols in design-time is impossible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:20:20+00:00Added an answer on May 21, 2026 at 7:20 am

    Doing this by hand is unpleasant, let a code generator do the job for you. Create a dummy form, drop a TLP on it. Get it the way you want it with the designer.

    Next, locate the form in the Solution Explorer window and open the node to the left of it. Double-click the Designer.cs file. Locate the code in the InitializeComponent method and copy/paste it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TableLayoutPanel that contains rows of labels. This control lives on form
I have a C# .NET 3.0 project that uses a TableLayoutPanel containing several rows
Stack-O, I have a TableLayoutPanel with 50 rows and 6 columns. That's all well
I want to have another copy of some control upon dragging and dropping it
I have added controls dynamically on runtime inside the rows of a tableLayoutpanel ,
This is really simple. I have a TableLayoutPanel that is populated with controls (just
I have a user control that contains a 2-column TableLayoutPanel and accepts commands to
I'm having trouble with a gradient drawing call. I have a Form that looks
I have a class which derived from the TableLayoutPanel. This class makeup the tabel
I'm making some controls which all have to share the same look and some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.