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?