Edytuj

Udostępnij za pośrednictwem


ColumnDefinitionCollection.IndexOf(ColumnDefinition) Method

Definition

Returns the index position of a given ColumnDefinition within a ColumnDefinitionCollection.

public:
 virtual int IndexOf(System::Windows::Controls::ColumnDefinition ^ value);
public int IndexOf (System.Windows.Controls.ColumnDefinition value);
abstract member IndexOf : System.Windows.Controls.ColumnDefinition -> int
override this.IndexOf : System.Windows.Controls.ColumnDefinition -> int
Public Function IndexOf (value As ColumnDefinition) As Integer

Parameters

value
ColumnDefinition

The ColumnDefinition whose index position is desired.

Returns

The index of value if found in the collection; otherwise, -1.

Implements

Examples

The following example demonstrates how to use the IndexOf method to determine the index position of a ColumnDefinition within a ColumnDefinitionCollection.

private void insertColAt(object sender, RoutedEventArgs e)
{
    colDef1 = new ColumnDefinition();
    grid1.ColumnDefinitions.Insert(grid1.ColumnDefinitions.Count, colDef1);
    tp2.Text = "ColumnDefinition added at index position " + grid1.ColumnDefinitions.IndexOf(colDef1).ToString();
}
Private Sub insertColAt(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim colDef1 As New ColumnDefinition()
    grid1.ColumnDefinitions.Insert(grid1.ColumnDefinitions.Count, colDef1)
    tp2.Text = "ColumnDefinition added at index position " + grid1.ColumnDefinitions.IndexOf(colDef1).ToString()
End Sub

To view the complete sample, see How to: Manipulate Columns and Rows by Using ColumnDefinitionsCollections and RowDefinitionsCollections.

Applies to

See also