Gets the column from the collection at the specified index.
[C#] In C#, this member is the indexer for the ColumnsCollection class.
[Visual Basic] Overloads Overridable Public Default ReadOnly Property Item( _ ByVal index As Integer _ ) As DataColumn [C#] public DataColumn this[ int index ] {virtual get;} [C++] public: __property virtual DataColumn* get_Item( int index ); [JScript] returnValue = ColumnsCollectionObject.Item(index); -or- returnValue = ColumnsCollectionObject(index);
[JScript] In JScript, you can use the default indexed properties defined by a type, but you cannot explicitly define your own. However, specifying the expando attribute on a class automatically provides a default indexed Item property whose type is Object and whose index type is String.
The DataColumn at the specified index.
Exception Type | Condition |
---|---|
IndexOutOfRangeException | The collection doesn't have a column at this index. |
The Contains method can be used to test for the existence of a column, which is useful before attempting to use Item property (ColumnsCollection indexer).
The following example uses the Item property (ColumnsCollection indexer) to print the ColumnName value of a DataColumn object specified by index. The example uses the DataTable contained by a System.WinForms.DataGrid control.
[Visual Basic]
Private Sub PrintColumnNamesByIndex() Dim cols As DataColumns Dim i As Integer ' Get the ColumnsCollection from a DataTable in a DataSet. cols = DataSet1.Tables("Orders").Columns ' Print each column's name using the Index. For i = 0 to cols.Count - 1 Console.WriteLine(cols(i)) Next i End Sub
ColumnsCollection Class | ColumnsCollection Members | System.Data Namespace | ColumnsCollection.Item Overload List | ColumnName | Contains | DataColumn