VGridControlBase.GetCellValue(BaseRow, Int32) Method
Returns the value of a cell.
Namespace: DevExpress.XtraVerticalGrid
Assembly: DevExpress.XtraVerticalGrid.v20.2.dll
NuGet Package: DevExpress.Win.VerticalGrid
Declaration
Parameters
Name | Type | Description |
---|---|---|
row | BaseRow | The row that contains the cell. |
recordIndex | Int32 | The index of the record that contains the cell. |
Returns
Type | Description |
---|---|
Object | An object that specifies the cell’s value. null (Nothing in Visual Basic) if no cell is found. |
Remarks
Use the GetCellValue or SetCellValue method to obtain or set a cell value. To identify the cell, use the field name (which specifies a row) and record index (which specifies a column). You can also use an EditorRow, MultiEditorRow, or RowProperties object to specify a row. For multi-editor rows (which display multiple cells in a single column), you should also specify the cell index. The image below illustrates cells in a single- and multi-editor row.
// Cell is identified by a field name and record index.
vGridControl.SetCellValue(fieldName: "Name", recordIndex: 0, value: "Touareg");
// Cell is identified by a single-editor row object and record index.
vGridControl.SetCellValue(gridRow: erName, recordIndex: 0, value: "Touareg");
// Cell is identified by a multi-editor row object, record index and cell index.
vGridControl.SetCellValue(meRow: merTransmmision, recordIndex: 0, cellIndex: 1, value: 8);
// Cell is identified by a row properties object and record index.
vGridControl.SetCellValue(props: merpTransmissionSpeeds, recordIndex: 0, value: 8);
If you obtain or set the focused row’s value, check if the focused row is an EditorRow or MultiEditorRow, and then use the method’s corresponding overload.
string focusedCellValue = string.Empty;
if (vGridControl1.FocusedRow is DevExpress.XtraVerticalGrid.Rows.EditorRow)
focusedCellValue = vGridControl1.GetCellValue(vGridControl1.FocusedRow, vGridControl1.FocusedRecord).ToString();
Important
If the specified value’s type and the data field’s type do not match, the InvalidValueException event is raised. See the following topic for more information: Validation.
Example
The following sample code handles the VGridControlBase.CellValueChanged event to change the processed row’s style if its summary data cells value is greater than 100,000. To get a cell’s value, the code uses the VGridControlBase.GetCellValue method.
using DevExpress.Utils;
using DevExpress.XtraVerticalGrid;
using DevExpress.XtraVerticalGrid.Rows;
using DevExpress.XtraVerticalGrid.Events;
private void vGridControl1_CellValueChanged(object sender, CellValueChangedEventArgs e) {
double sum = 0;
for (int i = 0; i < vGridControl1.RecordCount; i++)
sum += Convert.ToDouble(vGridControl1.GetCellValue(e.Row, i));
if (sum > 100000)
e.Row.Appearance.BackColor = Color.Red;
else
e.Row.Appearance.Options.UseBackColor = false;
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the GetCellValue(BaseRow, Int32) 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.