次の方法で共有


DataTableCollection.IndexOf メソッド

定義

指定した DataTable オブジェクトのコレクション内のインデックスを取得します。

オーバーロード

名前 説明
IndexOf(String, String)

指定した DataTable オブジェクトのコレクション内のインデックスを取得します。

IndexOf(DataTable)

指定した DataTable オブジェクトのインデックスを取得します。

IndexOf(String)

指定した名前の DataTable オブジェクトのコレクション内のインデックスを取得します。

IndexOf(String, String)

ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs
ソース:
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

注釈

TableName プロパティを使用して、DataTable オブジェクトの名前を指定します。

こちらもご覧ください

適用対象

IndexOf(DataTable)

ソース:
DataTableCollection.cs
ソース:
DataTableCollection.cs
ソース:
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
ソース:
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

注釈

TableName プロパティを使用して、DataTable オブジェクトの名前を指定します。

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

こちらもご覧ください

適用対象