Obtaining And Setting Cell Values
- 2 minutes to read
The ExpressVerticalGrid control displays data within cells. Each cell is uniquely identified by the row and record to which it belongs.
At runtime, end-users can easily navigate and edit cells. There are a number of options affecting the editing capabilities of the vertical grid:
the Row.Options.Focusing option allows/disallows focusing cells (thus affecting the ability to edit the cell content);
the Row.Properties.Options.Editing option enables/disables editing for a particular row;
the Grid.OptionsData.Editing option enables/disables editing for all vertical grid rows.
All the above-mentioned options affect end-user editing capabilities. If editing is not available to the end-user, cell values still can be accessed and modified by code. Accessing cell values differs according to the vertical grid data loading mode.
Obtaining and Setting Values in Bound Mode
When working with a data-aware vertical grid (TcxDBVerticalGrid), cell values can be accessed using TField members. The following code changes the value of the focused row to the “New Value” string:
var
AModelField: TField;
//...
with cxDBVerticalGrid1 do
begin
if Assigned(FocusedRow) then
begin
with DataController do
begin
//switching the grid's data controller to edit mode
Edit;
//obtaining the TField instance for the edited row
AModelField := DataSource.DataSet.FindField(TcxDBVerticalGridItemDataBinding(TcxEditorRow(FocusedRow).Properties.DataBinding).FieldName);
//specifying the new row value
AModelField.AsString := 'New Value';
//posting changes to the dataset
Post;
end;
end;
end;
//...
Obtaining and Setting Values in Unbound Mode
When working in unbound mode (cxVerticalGrid), the cell values are available via the Row.Properties.Value property.
The following example replaces the focused cell value with the Text property value from a TEdit:
//...
if Assigned(cxVerticalGrid1.FocusedRow) then
TcxEditorRow(cxVerticalGrid1.FocusedRow).Properties.Value := Edit1.Text;
//...