This documentation is archived and is not being maintained.

GridColumnStylesCollection.IndexOf Method

Gets the index of a specified DataGridColumnStyle.

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

public int IndexOf (
	DataGridColumnStyle element
public int IndexOf (
	DataGridColumnStyle element
public function IndexOf (
	element : DataGridColumnStyle
) : int
Not applicable.



The DataGridColumnStyle to find.

Return Value

The zero-based index of the DataGridColumnStyle within the GridColumnStylesCollection or -1 if no corresponding DataGridColumnStyle exists.

Use the Contains method to determine if a specific DataGridColumnStyle exists. If so, and you need the index of the element within the collection, use the IndexOf method.

The following code example uses the Contains method to determine if a given DataGridColumnStyle exists in a GridColumnStylesCollection. If so, the IndexOf method returns the index of the DataGridColumnStyle, and the Remove method is invoked with the index to remove the element from the collection.

function RemoveCol(dc : DataColumn){
  var myGridColumns : GridColumnStylesCollection =

    var i = myGridColumns.IndexOf(myGridColumns("FirstName"));

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0