DataRow.Item プロパティ (DataColumn, DataRowVersion)
指定した DataColumn に格納されているデータの指定したバージョンを取得します。
[C#] C# では、このプロパティは DataRow クラスのインデクサになります。
Overloads Public Default ReadOnly Property Item( _
ByVal column As DataColumn, _ ByVal version As DataRowVersion _) As Object
[C#]
public object this[DataColumncolumn,DataRowVersionversion] {get;}
[C++]
public: __property Object* get_Item(DataColumn* column,DataRowVersionversion);
[JScript]
returnValue = DataRowObject.Item(column, version);またはreturnValue = DataRowObject(column, version);
[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。
引数 [JScript]
- column
列に関する情報を格納する DataColumn 。 - version
必要な行のバージョンを指定する DataRowVersion 値の 1 つ。可能な値は、Default、Original、Current、および Proposed です。
パラメータ [Visual Basic, C#, C++]
- column
列に関する情報を格納する DataColumn 。 - version
必要な行のバージョンを指定する DataRowVersion 値の 1 つ。可能な値は、Default、Original、Current、および Proposed です。
プロパティ値
データを格納している Object 。
例外
例外の種類 | 条件 |
---|---|
ArgumentException | 列がこのテーブルに属していません。 |
ArgumentNullException | 引数 column が null です。 |
VersionNotFoundException | このバージョンのデータが行にありません。 |
解説
version は、 RowState プロパティとは異なります。引数 version は、列の元の値を基準にして、列に格納されているデータの状態を表します。
プロパティを設定するときに、 ColumnChanging イベントで例外が発生すると例外が生成されます。
直前の編集の場合、生成される可能性がある例外については EndEdit のトピックを参照してください。
使用例
[Visual Basic, C#, C++] DataGrid コントロールでクリックされたセルにある現在の値を取得する例を次に示します。
Private Sub DataGrid1_Click _
(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim currRow As DataRow
Dim myColumn As DataColumn
Dim dataGridTable As DataTable
dataGridTable = CType(DataGrid1.DataSource, DataTable)
' Set the current row using the RowNumber property of the CurrentCell.
currRow = dataGridTable.Rows(DataGrid1.CurrentRowIndex)
myColumn = dataGridTable.Columns(1)
' Get the value of the column 1 in the DataTable.
label1.Text = currRow(myColumn, DataRowVersion.Current).ToString()
End Sub
[C#]
private void DataGrid1_Click(object sender, System.EventArgs e) {
DataRow currRow;
DataColumn myColumn;
DataTable dataGridTable = (DataTable)DataGrid1.DataSource;
// Set the current row using the RowNumber property of the CurrentCell.
currRow = dataGridTable.Rows[DataGrid1.CurrentCell.RowNumber];
myColumn = dataGridTable.Columns[1];
// Get the value of the column 1 in the DataTable.
Console.WriteLine(currRow[myColumn, DataRowVersion.Current]);
}
[C++]
private:
void DataGrid1_Click(Object* /*sender*/, System::EventArgs* /*e*/) {
DataRow* currRow;
DataColumn* myColumn;
DataTable* dataGridTable = dynamic_cast<DataTable*>(DataGrid1->DataSource);
// Set the current row using the RowNumber property of the CurrentCell.
currRow = dataGridTable->Rows->Item[DataGrid1->CurrentCell.RowNumber];
myColumn = dataGridTable->Columns->Item[1];
// Get the value of the column 1 in the DataTable.
Console::WriteLine(currRow->Item[myColumn, DataRowVersion::Current]);
}
[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 ファミリ
参照
DataRow クラス | DataRow メンバ | System.Data 名前空間 | DataRow.Item オーバーロードの一覧 | DataRowVersion