Gets the table specified by its index.
[C#] In C#, this member is the indexer for the TablesCollection class.
[Visual Basic] Overloads Public Default ReadOnly Property Item( _ ByVal index As Integer _ ) As DataTable [C#] public DataTable this[ int index ] {get;} [C++] public: __property DataTable* get_Item( int index ); [JScript] returnValue = TablesCollectionObject.Item(index); -or- returnValue = TablesCollectionObject(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.
A DataTable.
Exception Type | Condition |
---|---|
IndexOutOfRangeException | The index doesn't exist in the collection. |
The Contains method can be used to determine if a table with a specified index exists.
If you have the name of a table, but not its index, use the IndexOf method to return the table's index.
The following example retrieves a DataTable by its index.
[Visual Basic]
Private Sub GetDataTableByIndex() Dim tablesCol As TablesCollection Dim dSet As DataSet ' Presuming a DataGrid is displaying more than one table, get its DataSet. Set dSet = DataGrid1.DataGridTable.DataTable.DataSet ' Get the TablesCollection. Set tablesCol = dSet.Tables ' Iterate through the collection to get each table name. Dim i As Integer For i = 0 To tablesCol.Count - 1 Console.WriteLine(TableCol(i).TableName) Next End Sub
TablesCollection Class | TablesCollection Members | System.Data Namespace | TablesCollection.Item Overload List | Contains | IndexOf | DataTable