DataRow.Item Property (Int32, DataRowVersion)
Gets the data stored in the column, specified by index and version of the data to retrieve.
Assembly: System.Data (in System.Data.dll)
- Type: System.Int32
The zero-based index of the column.
The columnIndex argument is out of range.
The data types of the value and the column do not match.
The row does not have this version of data.
An attempt was made to set a value on a deleted row.
You can only create or update a row after you call the BeginEdit method; similarly, the EndEdit method must be called to commit the edit. After you call the EndEdit method, and before you call 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. However, as soon as you call the AcceptChanges method, 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 returns the current value, whatever its version may be.
The BeginEdit method is called implicitly when you change the value of a data-bound control or when a DataRow object is added to the DataRowCollection; the EndEdit method is called implicitly when you call the following methods: the AcceptChanges method of the DataRow object, the AcceptChanges method of the DataTable object, or the CancelEdit method.
The version argument should not be confused with the RowState property. The version argument describes the state of the data that is contained by the column relative to the column's original value. The RowState property describes the state of the whole row relative to its parent DataTable.
When you set the property, an exception is generated if an exception occurs in the ColumnChanging event.
If this is an immediate edit, see EndEdit for the exceptions that can be generated.
Private Sub DataGrid1_Click _ (ByVal sender As System.Object, ByVal e As System.EventArgs) ' Set the current row using the RowNumber property of the CurrentCell. Dim currentRow As DataRow = CType(DataGrid1.DataSource, DataTable). _ Rows(DataGrid1.CurrentCell.RowNumber) ' Get the value of the column 1 in the DataTable. label1.Text = currentRow(1, DataRowVersion.Current).ToString() End Sub
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.