I've noticed that every control added to the TableLayoutPanel is given "Column" and "Row" properties.
How can I get access to these properties through code?
thanks:)

- 5,006
- 17
- 69
- 106
-
Is this Windows Forms ? You'll get better answers if you include that in tags. – driis Feb 09 '11 at 17:43
-
yes :) (a few more characters more so I can post this comment.) – Idov Feb 09 '11 at 17:45
4 Answers
These properties only exist in the Properties Window, magic provided by the IExtenderProvider interface. They don't exist at runtime. Extended properties are:
- ColumnSpan. Runtime: GetColumnSpan() and SetColumnSpan()
- RowSpan. Runtime: GetRowSpan() and SetRowSpan()
- Row. Runtime: GetRow() and SetRow()
- Cell. Runtime: GetCellPosition() and SetCellPosition()
- Column. Runtime: GetColumn() and SetColumn()
Obviously TLP was highly optimized to be used from the designer. It's kinda of a pain at runtime.

- 922,412
- 146
- 1,693
- 2,536
-
This is incorrect (although that may be due to the fact the the answer is 3 years old)... For anyone that finds this now the correct answer is: 'tableLayoutPanel1.(Get/Set)ColumnSpan(ControlName)' – Anthony Nichols Jun 24 '14 at 14:31
-
1
-
I see what you are saying. I skipped right over that because I though you were talking about running those on the control, not on the table. Also, the part about saying it was a pain threw me off. My-bad. – Anthony Nichols Jun 24 '14 at 22:37
Go here.
This properties are added by means of "extending properties", something that other controls like ToolTip
uses.

- 1
- 1

- 19,718
- 12
- 58
- 99
Although the properties designer shows the row and column as properties of the added control thay are set programatically using a method on the table layout panel itself (SetColumn(control, index) and SetRow(control, index)).
This pattern of behaviour is similar the tool tip component and the error component.

- 1,532
- 1
- 11
- 15
// Create TableLayoutPanel TableLayoutPanel tlp = new TableLayoutPanel();
// Set the BorderStyle to Inset tlp.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
// Grid has two columns
tlp.ColumnCount = 2;
// Grid has two rows
tlp.RowCount = 2;
// If grid is full add extra cells by adding column
tlp.GrowStyle = TableLayoutPanelGrowStyle.AddColumns;
// Padding (pixels)within each cell (left, top, right, bottom)
tlp.Padding = new Padding(1, 1, 4, 5);
// Add TableLayoutPanel to the Forms controls
this.Controls.Add(tlp);

- 4,099
- 7
- 30
- 56