6

I have a table layout that contains three rows and one column:

enter image description here

What I want is to hide the second row before the progress completes, like this:

enter image description here

On the internet, I found two things:

  1. Delete the row - I don't want to delete the row, just temporarily hide it!
  2. Set row height to 0 - didn't work, for some reason part of the inner data was still visible.

So how do I really HIDE the row. Not remove, not resize but actually hide it from view.

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • 3
    What tool did you use to do your UX mock-up? I like it! – STLDev May 04 '18 at 03:03
  • 1
    Did you try this? tableLayoutPanel1.RowStyles[1].SizeType = SizeType.Absolute; tableLayoutPanel1.RowStyles[1].Height = 0; ................OR....... tableLayoutPanel1.RowStyles[1] = new RowStyle(SizeType.Absolute, 0F); – Gaurang Dave May 04 '18 at 03:07
  • Possible duplicate of [Hide and show a cell of the TableLayoutPanel](https://stackoverflow.com/questions/3290414/hide-and-show-a-cell-of-the-tablelayoutpanel) – KOB May 04 '18 at 03:41

4 Answers4

13

Hiding and showing rows in a TableLayoutPanel is not really straightforward.

Based on your UI mock, I assume first and third rows are set to Absolute while second one is AutoSize or Percent. I am also assuming that Dock for panel is set to Fill. Now, here is what I would do in this scenario.

Add an empty row in the end with SizeType set to AutoSize. When the user action begins (say a button click) do the following:

// RowStyles index is index of the row you are dealing with
tableLayoutPanel1.RowStyles[1].SizeType = SizeType.Absolute;
tableLayoutPanel1.RowStyles[1].Height = 0;

Since there is an auto-sized row in the end, all the other rows would move up and your form will have empty space at the bottom. This will retain your desired layout. When the action is completed, you can set the row in question back to Percent or AutoSize.

danish
  • 5,550
  • 2
  • 25
  • 28
4

If the table layout row size style is autosize the show/hide behaviour can be achieved by setting the visible property of row content (e.g., groupbox) to be true or false.

Jie Zhao
  • 121
  • 1
  • 2
1

As Jie Zhao said.

If all your rows styles have the SizeType property set to Absolute, but the row style you want to hide is set to AutoSize, all you need to do is set the property Visible to False in every control inside the row style.

In my example, my TableLayoutPanel has three columns.

See example

label1.Visible = false;
label2.Visible = false;
label3.Visible = false;
MX_Alejandro
  • 11
  • 1
  • 2
0

Somehow danish suggestion is not working fine. There are still visible controls, depending on style- check box "clasic" disappears, meanwhile "box" style is a bit visible. TextBox is visible in "hidden" row and if you remove two rows, only then one Textbox is hidden.

And yes, there is extra autosize row and column with empty cells:

enter image description here

So, the only proper way is to hide the children:

For i = 0 To My_Table_layout_panel.Controls.Count - 1
                    If My_Table_layout_panel.GetRow(My_Table_layout_panel.Controls(i)) = LAST_RAM_ROW Then
                        My_Table_layout_panel.Controls(i).Hide()
                    End If
                Next

or show them:

For i = 0 To My_Table_layout_panel.Controls.Count - 1
                    If My_Table_layout_panel.GetRow(My_Table_layout_panel.Controls(i)) = LAST_RAM_ROW Then
                        My_Table_layout_panel.Controls(i).Show()
                    End If
                Next

Now it works like a charm. LAST_RAM_ROW is just the row to hide.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459