Click here to Skip to main content
14,970,019 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a normal Windows Form. Over it, i have a panel. On this Panel, i have a SplitContainer. In the SplitContainer.Panel2, there is a TableLayoutPanel. The Backcolor is set as Black and Forcolor is set to White in TableLayoutPanel. I have stretched the TablelayoutPanel to fit the panel2 of SplitContainer. Thats all the settings done.

Now, Whenever i am running the application and populating the table with the data, the TableLayoutPanel gets stretched. and displays outside the Base panel itself and the data seems to be displayed out of the form :(

Sometimes, the TableLayoutPanel itself will not get displayed on the SplitContainer.Panel2 :(

Please suggest what i need to do in order to make the TableLayoutPanel fit exactly in the SplitContainer.Panel2. It should show all the data in that much place only. If required we can provide scrollbars.

Below is the code snippet, Thanks:

private void button1_Click(object sender, EventArgs e)
    DataExtractor obj = new DataExtractor();

    var v = obj.GetAdminData();

    tableLayoutPanel1.Visible = false;
    tableLayoutPanel1.ColumnCount = 4;
    tableLayoutPanel1.RowCount = ((v.DOCREVISIONS.Length * 4) + 1 + (v.USEDLANGUAGES.L10.Length));

    Label labelLanguage = new Label();
    Label labelUsedLanguage = new Label();
    Label labelDocRevisions = new Label();

    labelLanguage.Text = "Language:";
    labelUsedLanguage.Text = "Used Language:";
    labelDocRevisions.Text = "Doc-Revisions:";

    ComboBox comboBoxLanguage = new ComboBox();
    comboBoxLanguage.SelectedIndex = 0;

    ComboBox comboBoxUsedLanguage = new ComboBox();
    foreach (LPLAINTEXT Lang in v.USEDLANGUAGES.L10)
    comboBoxUsedLanguage.SelectedIndex = 0;
    int index = 0;

    Label[] labelDocRevision = new Label[v.DOCREVISIONS.Length];
    Label[] labelRevision = new Label[v.DOCREVISIONS.Length];
    Label[] labelState = new Label[v.DOCREVISIONS.Length];
    Label[] labelTeamMember = new Label[v.DOCREVISIONS.Length];
    Label[] labelDate = new Label[v.DOCREVISIONS.Length];

    TextBox[] textBoxRevision = new TextBox[v.DOCREVISIONS.Length];
    TextBox[] textBoxState = new TextBox[v.DOCREVISIONS.Length];
    TextBox[] textBoxTeamMember = new TextBox[v.DOCREVISIONS.Length];
    TextBox[] textBoxDate = new TextBox[v.DOCREVISIONS.Length];

    foreach (DOCREVISION dcr in v.DOCREVISIONS)
        labelDocRevision[index] = new Label();
        labelRevision[index] = new Label();
        labelState[index] = new Label();
        labelTeamMember[index] = new Label();
        labelDate[index] = new Label();

        textBoxRevision[index] = new TextBox();
        textBoxState[index] = new TextBox();
        textBoxTeamMember[index] = new TextBox();
        textBoxDate[index] = new TextBox();

        labelDocRevision[index].Text = "DOCREVISION["+index.ToString()+"]:";
        labelRevision[index].Text = "Revision:";
        labelState[index].Text = "State:";
        labelTeamMember[index].Text = "TeamMemberRef:";
        labelDate[index].Text = "Date:";

        textBoxRevision[index].Text = dcr.REVISIONLABEL.Value.ToString();
        textBoxState[index].Text = dcr.STATE.Value.ToString();
        textBoxTeamMember[index].Text = dcr.TEAMMEMBERREF.Value.ToString();
        textBoxDate[index].Text = dcr.DATE.Value.ToString();


    // Add child controls to TableLayoutPanel and specify rows and column


    tableLayoutPanel1.Controls.Add(labelLanguage, 0, 0);
    tableLayoutPanel1.Controls.Add(labelUsedLanguage, 0, 1);
    tableLayoutPanel1.Controls.Add(labelDocRevisions, 0, 2);
    tableLayoutPanel1.Controls.Add(comboBoxLanguage, 1, 0);
    tableLayoutPanel1.Controls.Add(comboBoxUsedLanguage, 1, 1);

    // tableLayoutPanel1.Controls[0].Text = "test";

    int docRevRowSpacing = 2;
    for (int loop = 0; loop < index; loop++)
        tableLayoutPanel1.Controls.Add(labelDocRevision[loop], 1, docRevRowSpacing);
        tableLayoutPanel1.Controls.Add(labelRevision[loop], 2, docRevRowSpacing);
        tableLayoutPanel1.Controls.Add(labelState[loop], 2, docRevRowSpacing+1);
        tableLayoutPanel1.Controls.Add(labelTeamMember[loop], 2, docRevRowSpacing+2);
        tableLayoutPanel1.Controls.Add(labelDate[loop], 2, docRevRowSpacing+3);

        tableLayoutPanel1.Controls.Add(textBoxRevision[loop], 3, docRevRowSpacing);
        tableLayoutPanel1.Controls.Add(textBoxState[loop], 3, docRevRowSpacing+1);
        tableLayoutPanel1.Controls.Add(textBoxTeamMember[loop],3 , docRevRowSpacing+2);
        tableLayoutPanel1.Controls.Add(textBoxDate[loop], 3, docRevRowSpacing+3);

        docRevRowSpacing += 4;

    tableLayoutPanel1.Visible = true;
Updated 12-Jun-15 3:20am
[no name] 15-Jun-15 1:37am
Any suggestions guys :( ?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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