Gets the data stored at the column; the column is specified by name. Additionally, you can specify which version of the data to retrieve.
[C#] In C#, this member is the indexer for the DataRow class.
[Visual Basic] Overloads Public Default ReadOnly Property Item( _ ByVal columnName As String, _ ByVal version As DataRowVersion _ ) As Object [C#] public object this[ string columnName, DataRowVersion version ] {get;} [C++] public: __property Object* get_Item( String* columnName, DataRowVersion version ); [JScript] returnValue = DataRowObject.Item(columnName, version); -or- returnValue = DataRowObject(columnName, version);
[JScript] In JScript, you can use the default indexed properties defined by a type, but you cannot explicitly define your own. However, specifying the expando attribute on a class automatically provides a default indexed Item property whose type is Object and whose index type is String.
An Object that contains the data.
Exception Type | Condition |
---|---|
VersionNotFoundException | The row doesn't have this version of data. |
IndexOutOfRangeException | The column specified by columnName can't be found. |
InvalidCastException | The data types of the value and the column don't match. |
DeletedRowInaccessibleException | The row was deleted. |
The version shouldn't be confused with the RowState property. The version argument describes the state of the data contained by the column in relation to the column's original value. The RowState property describes the state of the entire row in relation to its parent DataTable.
When setting the property, an exception will be thrown if an exception occurs in the ColumnChanging event.
If this is an immediate edit, see EndEdit for the exceptions that can be thrown.
The following examples gets the current version of data at a clicked cell of a System.WinForms.DataGrid control.
[Visual Basic]
Private Sub DataGrid1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim currRow As DataRow ' Set the current row using the RowNumber property of the CurrentCell. currRow = DataGrid1.DataGridTable.DataTable. _ Rows(DataGrid1.CurrentCell.RowNumber) ' Get the current value of the column named "FirstName." label1.Text = CurrRow("FirstName", DataRowVersion.Current) End Sub
DataRow Class | DataRow Members | System.Data Namespace | DataRow.Item Overload List | DataRowVersion