Hide and show a cell of the TableLayoutPanel

Viewed 49168

My tablelayout panel has one column and three rows. (one docked to Fill panel in each cell.)

Now I would like to be able to hide/show the rows . I want only one row to be visible at any time ( based on a user selection of some radio buttons) and I want to to get resized so it fills all the area of the TableLayoutPanel.

How can I do that? Any thoughts?

8 Answers

To hide row try this!!

tableLayoutPanel1.RowStyles[1].SizeType = SizeType.Absolute;
tableLayoutPanel1.RowStyles[1].Height = 0;

I tried fooling around with the Height and SizeType properties, but it was giving me odd results. For example, the Labels on the target row were being hidden, but the TextBoxes were not.

Here is an extension class that I came up with using @arbiter's suggestion of hiding the children Controls of the row.

// these methods only works on rows that are set to AutoSize
public static class TableLayoutPanelExtensions
{

    public static void HideRows(this TableLayoutPanel panel, params int[] rowNumbers)
    {
        foreach (Control c in panel.Controls)
        {
            if (rowNumbers.Contains(panel.GetRow(c)))
                c.Visible = false;
        }
    }

    public static void ShowRows(this TableLayoutPanel panel, params int[] rowNumbers)
    {
        foreach (Control c in panel.Controls)
        {
            if (rowNumbers.Contains(panel.GetRow(c)))
                c.Visible = true;
        }

    }

}
Related