[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Collapse]Vertical Grid
   [Expand]Binding to Data
   [Collapse]Data Layout: Records, Rows and Cells
      Obtaining and Setting Cell Values
     Customization Form
     Data Layout: Records, Rows, and Cells
   [Expand]Data Editing and Validation
    Formatting Values
   [Expand]Drag and Drop
   [Expand]Appearance and Custom Painting
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Hit Information
    Batch Modifications
   [Expand]Member Tables
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Obtaining and Setting Cell Values

The vertical grids (VGridControl and PropertyGridControl) provide a number of ways to obtain and set cell values. This topic provides a list of all methods with examples. The common task that needs to be solved when accessing cell values is to identify the desired cell. The Cells Overview topic describes how this can be performed.

This topic has three sub-sections that describe various aspects of accessing cell values. The first is accessing the edited cell's value. The obvious shortcoming of this approach is that it can be used only when the grid is in the editing state. However, only this way of accessing cell values enables you to modify a cell value without closing the cell's editor. The second way to access cell values provides easy data modifications ability in Unbound Mode. Note that this way cannot be used with other modes. Lastly, the way to access cell values independently of any conditions is considered.

Important note: assigning a cell value of the wrong type raises an exception. You can provide a centralized control over such situations using the VGridControlBase.InvalidValueException event. Please refer to the Validation topic for information on how to do this.

Expanded Obtaining and Setting the Value of the Edited Cell

You can access the value of the cell being edited using the VGridControlBase.EditingValue property. Note that you must first check whether the grid is in the editing state before using this property. Otherwise it will return null (Nothing in Visual Basic) and assigning values to it will have no effect. To determine the current state of the vertical grid, you need to inspect the VGridControlBase.ActiveEditor property value. If this property value is a null reference, editing is not being performed at the moment.

The sample code below shows how to use the VGridControlBase.EditingValue property. It sets the edited cell's value to an empty string if the cell contains any text.

Expanded Obtaining and Setting Values in Unbound Mode

When a vertical grid works in Unbound Mode, each row item contains a single cell. The control is not bound to any data source and cell values are set using the RowProperties.Value property of the owning row items.

The sample code below shows how to use the RowProperties.Value property to access cell values. It assumes that the vertical grid control works in unbound mode and there are two rows within it. The first is the multi-editor row named rowPriceAndDiscount. It displays two cells representing the price of a product and the discount established. The second row is the editor row named rowRealPrice. It displays the price of the product taking the discount into account (the supposed layout of the control is shown in the image after the code). The sample code handles the VGridControlBase.CellValueChanged event. It is used to update the real price when either the product price or the discount is changed.

Expanded The Universal Way to Obtain and Set Cell Values

You can access cell values using the VGridControlBase.GetCellValue and VGridControlBase.SetCellValue methods. Both these methods have a number of overloads. The supplied overloads differ in how the accessed cell is specified.

The sample below shows how to obtain the string representation of the focused cell's value. The code uses the VGridControlBase.GetCellValue method overload that accepts the row and the record index as the parameters. Note that identifying a cell using only these two parameters implies that the cell resides within an editor row. Thus, row type checking is required to avoid errors.

The next sample code line shows how to set cell values using the VGridControlBase.SetCellValue method. It assigns zero to the cell residing within the focused record and belonging to the second item of the rowMPG row.

Is this topic helpful?​​​​​​​