次の方法で共有


DataTableCollection.IndexOf メソッド

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

オーバーロードの一覧

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function IndexOf(DataTable) As Integer

[C#] public virtual int IndexOf(DataTable);

[C++] public: virtual int IndexOf(DataTable*);

[JScript] public function IndexOf(DataTable) : int;

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function IndexOf(String) As Integer

[C#] public virtual int IndexOf(string);

[C++] public: virtual int IndexOf(String*);

[JScript] public function IndexOf(String) : int;

使用例

[Visual Basic, C#, C++] DataTableCollection 内の指定したテーブルのインデックスを返す例を次に示します。

[Visual Basic, C#, C++] メモ   ここでは、IndexOf のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Private Sub GetIndexes()
   Dim dSet As DataSet
   Dim tablesCol As DataTableCollection
   ' Get the DataSet of a DataGrid.
   dSet = CType(DataGrid1.DataSource, DataSet)
   ' Get the DataTableCollection through the Tables property.
   tablesCol = dSet.Tables
   ' Get the index of the table named "Authors", if it exists.
   If tablesCol.Contains("Authors") Then
      System.Diagnostics.Debug.WriteLine(tablesCol.IndexOf("Authors"))
   End If
End Sub

[C#] 
private void GetIndexes()
{
   DataSet dSet;
   DataTableCollection tablesCol;
   // Get the DataSet of a DataGrid.
   dSet = (DataSet)DataGrid1.DataSource;
   // Get the DataTableCollection through the Tables property.
   tablesCol = dSet.Tables;
   // Get the index of the table named "Authors", if it exists.
   if (tablesCol.Contains("Authors"))
      System.Diagnostics.Debug.WriteLine(tablesCol.IndexOf("Authors"));
}

[C++] 
private:
 void GetIndexes()
 {
    DataSet* dSet;
    DataTableCollection* tablesCol;
    // Get the DataSet of a DataGrid.
    dSet = dynamic_cast<DataSet*>(DataGrid1->DataSource);
    // Get the DataTableCollection through the Tables property.
    tablesCol = dSet->Tables;
    // Get the index of the table named "Authors", if it exists.
    if (tablesCol->Contains(S"Authors"))
       System::Diagnostics::Debug::WriteLine( __box(tablesCol->IndexOf(S"Authors")));
 }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

DataTableCollection クラス | DataTableCollection メンバ | System.Data 名前空間