TableLayoutControlCollection.Add Method (Control, Int32, Int32)


Adds the specified control to the collection and positions it at the specified cell.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public virtual void Add(
	Control control,
	int column,
	int row


Type: System.Windows.Forms.Control

The control to add.

Type: System.Int32

The column in which control will be placed.

Type: System.Int32

The row in which control will be placed.

Exception Condition

Either column or row is less than -1.

With Add, you can specify the cell position of control. You can assign control to a specific cell by providing both the column and row parameters, or you can specify only the column or row value and let the LayoutEngine place control at the next open cell. This is known as letting the control flow to its position in the TableLayoutPanel control.

Set column to -1 if you want control to occupy a fixed row position.

Set row to -1 if you want control to occupy a fixed column position.

If neither column nor row is -1, control will be added at the absolute position given by (column, row).

If you set both column and row to -1, control will flow to the first open position, with the specific flow behavior defined by the TableLayoutPanel.GrowStyle value. This is equivalent to using the Control.ControlCollection.Add method.

To get to the actual current position of a control, use the TableLayoutPanel.GetPositionFromControl method. This method takes into account the entire TableLayoutPanel control state, including column or row spanning and when the TableLayoutPanel.LayoutEngine has placed a control with its Column and Row properties set to -1.

.NET Framework
Available since 2.0
Return to top