ColumnView.SetRowCellValue(Int32, GridColumn, Object) Method

Assigns a value to a specific cell.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

public void SetRowCellValue(
    int rowHandle,
    GridColumn column,
    object _value
)
Public Sub SetRowCellValue(
    rowHandle As Integer,
    column As GridColumn,
    _value As Object
)

Parameters

Name Type Description
rowHandle Int32

An integer value representing a row handle containing the desired cell.

column GridColumn

A GridColumn object or descendant representing a column containing the desired cell.

_value Object

An object representing the value to be assigned.

Remarks

The method does nothing in the following cases:

  • the specified row handle is invalid or points to a group row;
  • the specified column object is a null reference or belongs to another View.
  • the specified row is a non-initialized New Item Row.

Changing a cell value raises the ColumnView.CellValueChanged event.

NOTE

Detail pattern Views do not contain data and they are never displayed within XtraGrid. So, the SetRowCellValue member must not be invoked for these Views. The SetRowCellValue member can only be used with real Views that are displayed within the Grid Control. The real Views with which an end-user interacts at runtime can be accessed using the following methods.

Examples

The code sample below iterates through grid records and reduces the "Price" column values by 10 percent.

private void UpdatePrice(DevExpress.XtraGrid.Views.Base.ColumnView View) {
   // Obtain the Price column. 
   DevExpress.XtraGrid.Columns.GridColumn col = View.Columns.ColumnByFieldName("Price");
   if (col == null) return;
   View.BeginSort();
   try {
      // Obtain the number of data rows. 
      int dataRowCount = View.DataRowCount;
      // Traverse data rows and change the Price field values. 
      for (int i = 0; i < dataRowCount; i++) {
         object cellValue = View.GetRowCellValue(i, col);
         double newValue = Convert.ToDouble(cellValue) * 0.9;
         View.SetRowCellValue(i, col, newValue);
      }
   } finally { View.EndSort(); }
}
See Also