TableLayoutPanel.GetControlFromPosition(Int32, Int32) Method

Definition

Returns the child control occupying the specified position.

C#
public System.Windows.Forms.Control GetControlFromPosition(int column, int row);
C#
public System.Windows.Forms.Control? GetControlFromPosition(int column, int row);

Parameters

column
Int32

The column position of the control to retrieve.

row
Int32

The row position of the control to retrieve.

Returns

The child control occupying the specified cell; otherwise, null if no control exists at the specified column and row, or if the control has its Visible property set to false.

Exceptions

Either column or row (or both) is less than 0.

Examples

The following code example enumerates all the cell positions in the TableLayoutPanel by looping through the columns and rows given by ColumnCount and RowCount, and then calling the GetControlFromPosition method to retrieve the control at each cell.

C#
private void getcontrolFromPosBtn_Click(
    System.Object sender, 
    System.EventArgs e)
{
    int i = 0;
    int j = 0;
    Trace.WriteLine(this.TableLayoutPanel1.ColumnCount);
    Trace.WriteLine(this.TableLayoutPanel1.RowCount);

    for(i=0; i<=this.TableLayoutPanel1.ColumnCount; i++)
    {
        for(j=0; j<=this.TableLayoutPanel1.RowCount; j++)
        {
            Control c = this.TableLayoutPanel1.GetControlFromPosition(i, j);

            if( c != null )
            {
                Trace.WriteLine(c.ToString());
            }
        }
    }
}

Remarks

The column and row position values are zero based.

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

See also