Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TableLayoutPanel.GetControlFromPosition Method

Returns the child control occupying the specified position.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
public Control GetControlFromPosition(
	int column,
	int row
)

Parameters

column
Type: System.Int32
The column position of the control to retrieve.
row
Type: System.Int32
The row position of the control to retrieve.

Return Value

Type: System.Windows.Forms.Control
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.
ExceptionCondition
ArgumentException

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

The column and row position values are zero based.

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.


    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());
                }
            }
        }
    }


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.