Skip to main content
A newer version of this page is available. .

ColumnView.GetRowCellValue(Int32, String) Method

Gets the value of the specified cell in the grid’s data source.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v19.2.dll

Declaration

public virtual object GetRowCellValue(
    int rowHandle,
    string fieldName
)

Parameters

Name Type Description
rowHandle Int32

An integer value representing the handle of the row in which the desired cell resides.

fieldName String

A string representing the field name whose value is to be returned. This parameter can refer to any field in the data source, even if the current View does not contain a GridColumn referring to this field.

Returns

Type Description
Object

An object that is the specified cell’s value.

If the required value is not found in the data source (e.g., if the specified field name does not exist), the method returns null (Nothing in Visual Basic).

In Instant Feedback Mode, an invalid “Non-loaded Value” is immediately returned if the requested cell is not currently loaded.

Remarks

The method returns null (Nothing in Visual Basic) in the following cases:

  • the specified row handle doesn’t point to any of the rows within the current View or points to a group row;
  • the specified field doesn’t exist in the data source.

To get the cell’s displayed value, the ColumnView.GetRowCellDisplayText method can be used.

For more information on row handles, refer to the Rows document.

Note

In Instant Feedback Mode, this GetRowCellValue method has limitations. It returns a correct value only if the target row has been loaded. Otherwise, it returns a “Non-loaded Value”. You can check to see whether or not the returned value is the “Non-loaded Value” by calling the static BaseEdit.IsNotLoadedValue method.

If you require this value right away (e.g., on a Custom Draw event), skip this value by adding a code, similar to the following:

private void gridView1_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e) {
    GridView view = sender as GridView;
    int index = view.GetDataRowHandleByGroupRowHandle(e.RowHandle);
    var cellValue = view.GetRowCellValue(index, "Mode");
    if (BaseEdit.IsNotLoadedValue(cellValue)) {
        ((GridGroupRowInfo)e.Info).GroupText = "Loading...";
    }
    else {
        int mode = (int)cellValue;
        ((GridGroupRowInfo)e.Info).GroupText += "custom " + mode;
    }
}

Note

Detail pattern Views do not contain data and they are never displayed within XtraGrid. So, the GetRowCellValue member must not be invoked for these Views. The GetRowCellValue 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.

Example

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(); }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetRowCellValue(Int32, String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also