DataTableCollection.IndexOf Метод

Определение

Получает индекс указанного объекта DataTable в коллекции.

Перегрузки

IndexOf(String, String)

Получает индекс указанного объекта DataTable в коллекции.

IndexOf(DataTable)

Возвращает индекс указанного объекта DataTable.

IndexOf(String)

Получает индекс объекта DataTable с указанным именем в коллекции.

IndexOf(String, String)

Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs

Получает индекс указанного объекта DataTable в коллекции.

public:
 int IndexOf(System::String ^ tableName, System::String ^ tableNamespace);
public int IndexOf (string tableName, string tableNamespace);
member this.IndexOf : string * string -> int
Public Function IndexOf (tableName As String, tableNamespace As String) As Integer

Параметры

tableName
String

Имя искомого объекта DataTable.

tableNamespace
String

Имя пространства имен объекта DataTable, в котором осуществляется поиск.

Возвращаемое значение

Индекс (с нуля) объекта DataTable с указанным именем или -1, если таблица не существует в коллекции.

Примеры

В следующем примере возвращается индекс именованной таблицы в DataTableCollection.

private void GetIndexes()
{
    // Get the DataSet of a DataGrid.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection through the Tables property.
    DataTableCollection tables = thisDataSet.Tables;

    // Get the index of the table named "Authors", if it exists.
    if (tables.Contains("Authors"))
        System.Diagnostics.Debug.WriteLine(tables.IndexOf("Authors"));
}
Private Sub GetIndexes()
   ' Get the DataSet of a DataGrid.
   Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

   ' Get the DataTableCollection through the Tables property.
   Dim tables As DataTableCollection = thisDataSet.Tables

   ' Get the index of the table named "Authors", if it exists.
   If tables.Contains("Authors") Then
      System.Diagnostics.Debug.WriteLine(tables.IndexOf("Authors"))
   End If
End Sub

Комментарии

Имя DataTable объекта указывается с помощью TableName свойства .

См. также раздел

Применяется к

IndexOf(DataTable)

Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs

Возвращает индекс указанного объекта DataTable.

public:
 int IndexOf(System::Data::DataTable ^ table);
public:
 virtual int IndexOf(System::Data::DataTable ^ table);
public int IndexOf (System.Data.DataTable? table);
public int IndexOf (System.Data.DataTable table);
public virtual int IndexOf (System.Data.DataTable table);
member this.IndexOf : System.Data.DataTable -> int
abstract member IndexOf : System.Data.DataTable -> int
override this.IndexOf : System.Data.DataTable -> int
Public Function IndexOf (table As DataTable) As Integer
Public Overridable Function IndexOf (table As DataTable) As Integer

Параметры

table
DataTable

Объект DataTable, который требуется найти.

Возвращаемое значение

Индекс (с нуля) таблицы или значение -1, если таблица не найдена в коллекции.

Примеры

В следующем примере возвращается индекс каждой таблицы в DataTableCollection.

private void GetIndexes()
{
    // Get the DataSet of a DataGrid.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection through the Tables property.
    DataTableCollection tables = thisDataSet.Tables;

    // Get the index of each table in the collection.
    foreach (DataTable table in tables)
        System.Diagnostics.Debug.WriteLine(tables.IndexOf(table));
}
Private Sub GetIndexes()
    ' Get the DataSet of a DataGrid.
    Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

    ' Get the DataTableCollection through the Tables property.
    Dim tables As DataTableCollection = thisDataSet.Tables
    Dim table As DataTable

    ' Get the index of each table in the collection.
    For Each table In tables
       System.Diagnostics.Debug.WriteLine(tables.IndexOf(table))
    Next
End Sub

Комментарии

Используйте метод , IndexOf чтобы определить точный индекс заданной таблицы.

Перед вызовом IndexOfможно проверить существование таблицы (указанной индексом или именем) с помощью Contains метода .

См. также раздел

Применяется к

IndexOf(String)

Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs
Исходный код:
DataTableCollection.cs

Получает индекс объекта DataTable с указанным именем в коллекции.

public:
 int IndexOf(System::String ^ tableName);
public:
 virtual int IndexOf(System::String ^ tableName);
public int IndexOf (string? tableName);
public int IndexOf (string tableName);
public virtual int IndexOf (string tableName);
member this.IndexOf : string -> int
abstract member IndexOf : string -> int
override this.IndexOf : string -> int
Public Function IndexOf (tableName As String) As Integer
Public Overridable Function IndexOf (tableName As String) As Integer

Параметры

tableName
String

Имя искомого объекта DataTable.

Возвращаемое значение

Индекс (с нуля) объекта DataTable с указанным именем или -1, если таблица не существует в коллекции.

Примеры

В следующем примере возвращается индекс именованной таблицы в DataTableCollection.

private void GetIndexes()
{
    // Get the DataSet of a DataGrid.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection through the Tables property.
    DataTableCollection tables = thisDataSet.Tables;

    // Get the index of the table named "Authors", if it exists.
    if (tables.Contains("Authors"))
        System.Diagnostics.Debug.WriteLine(tables.IndexOf("Authors"));
}
Private Sub GetIndexes()
   ' Get the DataSet of a DataGrid.
   Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

   ' Get the DataTableCollection through the Tables property.
   Dim tables As DataTableCollection = thisDataSet.Tables

   ' Get the index of the table named "Authors", if it exists.
   If tables.Contains("Authors") Then
      System.Diagnostics.Debug.WriteLine(tables.IndexOf("Authors"))
   End If
End Sub

Комментарии

Имя DataTable объекта указывается с помощью TableName свойства .

Этот метод возвращает значение -1, если две или более таблиц имеют одно и то же имя, но разные пространства имен. Вызов не последует, если имеется какая-либо неопределенность при сопоставлении имени таблицы точно одной таблице.

См. также раздел

Применяется к