NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

DataRow.Item (DataColumn)

Gets or sets the data stored at the DataColumn for this row.

[C#] In C#, this member is the indexer for the DataRow class.

[Visual Basic]
Overloads Public Default Property Item( _
   ByVal column As DataColumn _
) As Object
[C#]
public object this[
   DataColumn column
] {get; set;}
[C++]
public: __property Object* get_Item(
   DataColumn* column
);
public: __property void set_Item(
   DataColumn* column,
   Object*
);
[JScript]
returnValue = DataRowObject.Item(column);
DataRowObject.Item(column) = returnValue;
-or-
returnValue = DataRowObject(column);
DataRowObject(column) = returnValue;

[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.

Arguments [JScript]

column
A DataColumn that contains the data.

Parameters [Visual Basic, C#, C++]

column
A DataColumn that contains the data.

Property Value

An Object that contains the data.

Exceptions

Exception Type Condition
ArgumentNullException The column is null.
ArgumentException The column doesn't belong to this table.
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.

Remarks

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.

Example [Visual Basic]

The following examples demonstrate the use of the Item property (DataRow indexer) to get and set the value of a given column index. The first example gets the value of the first column in any row that a user clicks in a System.WinForms.DataGrid control. The second sets a value passed as an argument to the method.

[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)
   Dim myCol As DataColumn
   myCol = DataGrid1.DataGridTable.DataTable.Columns(1)
   ' Get the value of the column 1 in the DataTable.
   label1.Text = CurrRow(myCol)
End Sub
Private Sub SetDataRowValue(ByVal myGrid As DataGrid, ByVal newVal As Object)
   ' Set the value of a column in the last row of a DataGrid.
   Dim t As DataTable
   t = mygrid.DataGridTable.DataTable
   Dim myRow As DataRow
   myRow = t.Rows(t.Rows.Count - 1)
   Dim myCol As DataColumn
   myCol = t.Columns("FirstName")
   myRow(myCol)= newVal
End Sub

See Also

DataRow Class | DataRow Members | System.Data Namespace | DataRow.Item Overload List