NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

GridColumnsCollection.IndexOf

Gets the index of a specified DataGridColumn.

[Visual Basic]
Public Function IndexOf( _
   ByVal element As DataGridColumn _
) As Integer
[C#]
public int IndexOf(
   DataGridColumn element
);
[C++]
public: int IndexOf(
   DataGridColumn* element
);
[JScript]
public function IndexOf(
   element : DataGridColumn
) : int;

Parameters

element
A DataGridColumn to find.

Return Value

The zero-based index of the TBD within the GridColumnsCollection or-1 if no corresponding DataGridColumn exists.

Remarks

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

Example [Visual Basic]

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

[Visual Basic]

Private Sub RemoveCol(ByVal dc As DataColumn) 
   Dim dgCols As GridColumnsCollection
   Set dgCols = DataGrid1.GridColumns
   If dgCols.Contains(dc) Then
      Dim i As Integer
      i = dgCols.IndexOf(dgCols(dc))
      ' If it's not the 0-th element in the collection, remove it.
      If i > 0 Then dgCols.Remove i
   End If
End Sub

See Also

GridColumnsCollection Class | GridColumnsCollection Members | System.WinForms Namespace | Contains | DataGridColumn | Remove | Item