TableLayoutControlCollection.Add(Control, Int32, Int32) Method

Definition

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

public virtual void Add(System.Windows.Forms.Control control, int column, int row);

Parameters

control
Control

The control to add.

column
Int32

The column in which control will be placed.

row
Int32

The row in which control will be placed.

Exceptions

Either column or row is less than -1.

Remarks

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.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also