Export (0) Print
Expand All

TableLayoutPanel.GetControlFromPosition Method

Returns the child control occupying the specified position.

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

'Declaration
Public Function GetControlFromPosition ( _
	column As Integer, _
	row As Integer _
) As Control

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, Nothing 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 Sub getcontrolFromPosBtn_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles getcontrolFromPosBtn.Click

    Dim i As Integer = 0
    Dim j As Integer = 0
    Trace.WriteLine(Me.TableLayoutPanel1.ColumnCount)
    Trace.WriteLine(Me.TableLayoutPanel1.RowCount)

    For i = 0 To Me.TableLayoutPanel1.ColumnCount
        For j = 0 To Me.TableLayoutPanel1.RowCount

            Dim c As Control = Me.TableLayoutPanel1.GetControlFromPosition(i, j)

            If c IsNot Nothing Then

                Trace.WriteLine(c.ToString())

            End If 
        Next 
    Next 

End Sub

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft