コレクション内の、指定した名前の DataTable オブジェクトのインデックスを取得します。
Overloads Public Overridable Function IndexOf( _
ByVal tableName As String _) As Integer
[C#]
public virtual int IndexOf(stringtableName);
[C++]
public: virtual int IndexOf(String* tableName);
[JScript]
public function IndexOf(
tableName : String) : int;
パラメータ
- tableName
検索する DataTable オブジェクトの名前。
戻り値
指定した名前の DataTable の 0 から始まるインデックス番号。このテーブルがコレクション内にない場合は -1。
解説
TableName プロパティを使用して DataTable オブジェクトの名前を指定します。
使用例
[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
' 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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: 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