TableLayoutPanel Styles

Posted by on October 23, 2007

Setting Styles:

In the midst of working with the tablelayoutpanel I found I needed to control the styles of the cells. There is a lot to cover for controlling the rows and columns, so for now I am just going to cover the basics. The row styles are controlled by the TableLayoutRowStyle class which is contained in the TableLayoutRowStyleCollection. The column styles are controlled by the TableLayoutColumnStyle class which is contained in the TableLayoutColumnStyleCollection. To update a specific row to have a set style you would insert a style into the collection at the index corresponding to the row index. So, for example, if I want to update my 3rd row of 5 to be 200 pixels tall instead of the default then I would add the following code:

tablePanel.RowStyles.Insert(2, New RowStyle(SizeType.Absolute,200)) 

To update a column to be a specific size, ex. Fit contents, then I would add the following code:

tablePanel.ColumnStyles.Insert(1,New ColumnStyle(SizeType.AutoSize)) 

A common need to change the styles would be if you were creating a header column that only needed to be 50 pixels high and the rest of your columns were 150 pixels high. I will be adding more examples for the tablelayoutpanel soon.

(this was originally posted on my original blog on 6/27/2006)


Comments are closed.