System.Data Namespace DataColumnCollection Class
Returns the index of a specified DataColumn object.
[ VB ]
Overloads Overridable Public Function IndexOf ( _
ByVal column As DataColumn _
) As Integer
[ C# ]
public virtual int IndexOf (
DataColumn column
);
[ C++ ]
public: virtual int IndexOf (
DataColumn* column
);
[ JScript ]
public function IndexOf (
column : DataColumn
) : int;
- column
- The DataColumn to find.
The index of the DataColumn if it is in the collection; otherwise, -1.
Use the IndexOf method to determine the index of a given column.
Before calling IndexOf, you can test for the existence of a column by using the Contains method.
The following example returns the index of each column in a DataColumnCollection.
private void GetIndexes ( DataTable myTable ) {
DataColumnCollection myCols = myTable.Columns;
// get the index of each column in the collection.
foreach ( DataColumn col in myCols ) {
Response.Write ( myCols.IndexOf ( col ) );
}
}
Private Sub GetIndexes ( ByVal myTable As DataTable )
Dim myCols As DataColumnCollection = myTable.Columns
Dim col As DataColumn
' get the index of each column in the collection.
For Each col In myCols
Response.Write ( myCols.IndexOf ( col ) )
Next
End Sub |
|
C# |
VB |
DataColumnCollection Members DataColumnCollection.IndexOf Overload List Contains