IndexOf Method

ColumnDefinitionCollection.IndexOf Method (ColumnDefinition)


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

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

public int IndexOf(
	ColumnDefinition value


Type: System.Windows.Controls.ColumnDefinition

The ColumnDefinition whose index position is desired.

Return Value

Type: System.Int32

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

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

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

.NET Framework
Available since 3.0
Return to top
© 2016 Microsoft