This documentation is archived and is not being maintained.

DataRow.Item Property (Int32, DataRowVersion)

Gets the data stored in the column, specified by index and version of the data to retrieve.

Namespace: System.Data
Assembly: System.Data (in system.data.dll)

public Object this [
	int columnIndex,
	DataRowVersion version
] { get; 
/** @property */
public Object get_Item (int columnIndex, DataRowVersion version)

JScript supports the use of indexed properties, but not the declaration of new ones.

Parameters

columnIndex

The zero-based index of the column.

version

One of the DataRowVersion values that specifies the row version that you want. Possible values are Default, Original, Current, and Proposed.

Property Value

An Object that contains the data.

Exception typeCondition

IndexOutOfRangeException

The columnIndex argument is out of range.

InvalidCastException

The data types of the value and the column do not match.

VersionNotFoundException

The row does not have this version of data.

DeletedRowInaccessibleException

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.

NoteNote

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.

By contrast, the DataRowVersion enumeration Current returns the version of the data after the EndEdit method has been called.

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.

The following example gets the current value of a column through the Item property of the DataRow object.

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 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Show: