指定した DataTable オブジェクトのインデックスを取得します。
Overloads Public Overridable Function IndexOf( _
ByVal table As DataTable _) As Integer
[C#]
public virtual int IndexOf(DataTabletable);
[C++]
public: virtual int IndexOf(DataTable* table);
[JScript]
public function IndexOf(
table : DataTable) : int;
パラメータ
- table
検索する DataTable 。
戻り値
このテーブルの 0 から始まるインデックス番号。テーブルがコレクション内に存在しない場合は -1。
解説
IndexOf メソッドを使用して、特定のテーブルの正確なインデックスを確認します。
IndexOf を呼び出す前に Contains メソッドを使用して、(インデックスまたは名前で指定する) テーブルがあるかどうかを確認できます。
使用例
[Visual Basic, C#, C++] DataTableCollection 内の各テーブルのインデックスを返す例を次に示します。
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
Dim t As DataTable
' Get the index of each table in the collection.
For Each t In tablesCol
System.Diagnostics.Debug.WriteLine(tablesCol.IndexOf(t))
Next
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 each table in the collection.
foreach (DataTable t in tablesCol)
System.Diagnostics.Debug.WriteLine(tablesCol.IndexOf(t));
}
[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 each table in the collection.
System::Collections::IEnumerator* myEnum = tablesCol->GetEnumerator();
while (myEnum->MoveNext())
{
DataTable* t = __try_cast<DataTable*>(myEnum->Current);
System::Diagnostics::Debug::WriteLine( __box(tablesCol->IndexOf(t)));
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
DataTableCollection クラス | DataTableCollection メンバ | System.Data 名前空間 | DataTableCollection.IndexOf オーバーロードの一覧 | IndexOf | TableName | Remove