Gets the data stored at the column, specified by index and 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 columnIndex As Integer, _ ByVal version As DataRowVersion _ ) As Object [C#] public object this[ int columnIndex, DataRowVersion version ] {get;} [C++] public: __property Object* get_Item( int columnIndex, DataRowVersion version ); [JScript] returnValue = DataRowObject.Item(columnIndex, version); -or- returnValue = DataRowObject(columnIndex, 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 columnIndex argument is out of range. |
InvalidCastException | The data types of the value and the column don't match. |
DeletedRowInaccessibleException | An attempt was made to set a value on a deleted row. |
You can only create or update a row after calling the BeginEdit method; similarly, the EndEdit method must be called to commit the edit. After calling the EndEdit method, and before calling the AcceptChanges method, internal representations of the original and new proposed values are stored. Therefore, until you call the AcceptChanges, you can use the version argument to specify which version of a column's value you need, either the DataRowVersion.Original or DataRowVersion.Proposed. Once you call the AcceptChanges method, however, the version of the column reverts to DataRowVersion.Original. If the row is new, you can also pass DataRowVersion.Default for the parameter to retrieve the column's default value. When passing DataRowVersion.Current, the property will return the current value, whatever its version may be.
Note The BeginEdit method is called implicitly when you change the value of a databound control or when a DataRow object is added to the RowsCollection; the EndEdit method is called implicitly when calling the following methods: the DataRow object's AcceptChanges method, the DataTable object's AcceptChanges method, or the CancelEdit method.
By contrast, the DataRowVersion enumeration Current returns the version of the data after the EndEdit method has been called.
The version argument 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 example gets the current value of a column through the DataRow object's Item property (DataRow indexer).
[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 value of the column 1 in the DataTable. label1.Text = CurrRow(1, DataRowVersion.Current) End Sub
DataRow Class | DataRow Members | System.Data Namespace | DataRow.Item Overload List