Gets or sets all of the values for this row through an array.
[Visual Basic] Public Property ItemArray As Object () [C#] public object[] ItemArray {get; set;} [C++] public: __property Object* get_ItemArray(); public: __property void set_ItemArray(Object*[]); [JScript] public function get ItemArray() : Object[]; public function set ItemArray(Object[]);
An array of type Object.
Exception Type | Condition |
---|---|
ArgumentException | The array is larger than the number of columns in the table. |
InvalidCastException | A value in the array doesn't match its DataType in its respective DataColumn. |
ConstraintException | An edit broke a constraint. |
ReadOnlyException | An edit tried to change the value of a read-only column. |
NoNullAllowedException | An edit tried to put a null value in a column where the DataColumn object's AllowNull is false. |
DeletedRowInaccessibleException | The row has been deleted. |
If a DataColumn has its DefaultValue property set, pass a a null reference (in Visual Basic Nothing) in the array to set the default value for that column. Similarly, if a column has its AutoIncrement property set to true, pass the a null reference (Nothing) in the array to set the automatically generated value for the row.
An exception can occur if a user throws an exception in the ColumnChanging event, or the RowChanging event.
The following examples show how to get and set values using the ItemArray property.
[Visual Basic]
Private Sub GetArray() Dim currRow As DataRow currRow = DataGrid1.DataGridTable.DataTable.Rows(DataGrid1.CurrentCell.RowNumber) Dim myArray() As Object myArray = currRow.ItemArray Dim i As Integer Dim strTemp As String For i = 0 To UBound(myarray) strTemp &= myArray(i) & vbcrlf Next label1.Text = strtemp End Sub Private Sub SetArray() Dim myArray(1) As Object ' Use Object.Empty to set the default value of a column. myArray(0) = null myArray(1) = "Item 1" Dim currRow As DataRow currRow = DataGrid1.DataGridTable.DataTable.Rows(DataGrid1.CurrentCell.RowNumber) currRow.ItemArray = myarray End Sub
DataRow Class | DataRow Members | System.Data Namespace | AcceptChanges | AutoIncrement | DataColumn