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 の 0 から始まるインデックス番号。このテーブルがコレクション内に存在しない場合は -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

戻り値

テーブルの 0 から始まるインデックス番号。コレクション内でそのテーブルが見つからなかった場合は -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 の 0 から始まるインデックス番号。このテーブルがコレクション内に存在しない場合は -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 して指定します。

このメソッドは、2 つ以上のテーブルの名前が同じでも名前空間が異なる場合、-1 を返します。 1 つのテーブル名を正確に 1 つのテーブルに一致させるときにあいまいな点があると、この呼び出しは成功しません。

こちらもご覧ください

適用対象