0

Simply put, I am trying to add labels dynamically into a TableLayoutPanel that can be invisible and, in that case, setting the height to 0 to avoid awkward empty rows.

(I need this to work like an accordion, and I am using a TableLayout because later I will need to use complex controls such as treeViews):

while index < myDataTable.rows.count
    dim myLabel as new Label
    myLabel.Name = myDataTable.rows(index)("labelText").toString
    myLabel.Text = myDataTable.rows(index)("labelText").toString

    myTableLayout.controls.Add(myLabel, 0, index)

    If cbool(row("initialyVisible")) then
        myTableLayout.GetControlFromPosition(0, index).Visible = true
        myTableLayout.RowStyles.Add(New RowStyle(SizeType.Absolute, 150))
    else
        myTableLayout.GetControlFromPosition(0, index).Visible = false
        myTableLayout.RowStyles.Add(New RowStyle(SizeType.Absolute, 0))
    endif
    index = index + 1
end while

This works well.

However, during the execution, the visible status of these labels + rows height might change:

If visibleFlag = true Then
   myTableLayout.RowStyles(i).Height = 150
   myTableLayout.GetControlFromPosition(0, i).Visible = True
Else
   myTableLayout.RowStyles(i).Height = 0
   myTableLayout.GetControlFromPosition(0, i).Visible = false
End If

Causing the 2 problems illustrated in this image. Anything that can be done?

Jaime Oliveira
  • 751
  • 1
  • 5
  • 13
  • 1
    Why not try [Removing a specific Row in TableLayoutPanel](http://stackoverflow.com/q/15535214/719186) – LarsTech Oct 28 '15 at 17:43
  • You mean removing a specific row only to add it later again? Each of this hidden rows may very well need to be shown, depending on conditions. – Jaime Oliveira Oct 29 '15 at 08:31
  • If all you are showing are labels, then a DataGridView control might be a better choice. The TableLayoutPanel control has some weird quirks. – LarsTech Oct 29 '15 at 14:30

0 Answers0