Documents
NextGrid & NextDBGrid
- Html Column Tutorial
- Upgrade existing projects for loading changes
- NextGrid Vista Style
- Edit events in NextGrid
- NextGrid How To
- Integrating Inplace Editors
- InputLine Tutorial
- NextGrid Slide Style Tutorial
- Using Editors in runtime
- FieldChooser Tutorial
- Grid Report Tutorial
NextGrid
- TreeColumn Tutorial
- NextGrid Quick Start
- Custom Draw in NextGrid
- Export to XML from NextGrid
- Optimize NextGrid
- NextGrid Custom Sorting
- VirtualColumn Tutorial
- Graphic Column Tutorial
NextDBGrid
- NextDBGrid Quick Start
- NextDBGrid Events
- NextDBGrid How To
- Sorting records in NextDBGrid
- LookupColumn Tutorial
NextInspector
- ToolbarItem tutorial
- NextInspector Advanced tutorial
- NextDBInspector Tutorial
- NextInspector Item Types
- Map VCL property to item
- NextInspector Quick Start
NextSheet
NextCollection
- NxAlertWindow Tutorial
- NxInfoPanel Tutorial
- Vista Styled Panels
- NxPathControl and NxNotebook tutorial
- NxPathControl Quick Start
- NxFlipPanel and NxHeaderPanel Quick Start
- NxOutlookBar Tutorial
- NxPageControl and NxNotebook Quick Start
- NxButton Tutorial
Misc
- Component Names Change
- NxComboBox styles
- Numeric FormatMask
- NxVirtualDataSet tutorial
- DateTime FormatMask
- NxPreview Quick Start
- Quick update
- 32bit Bitmaps Tutorial
- Enable typing unicode characters in InplaceEditors
- Using NxColorScheme
- NxProgress Tutorial
- NxAutoCompletion Tutorial
Labs
NextGrid .NET
VirtualColumn Tutorial
Related Articles:
Info
- Skill:
- Version: 1.0.0
- Author: Wim van der Vegt
- Created:
- Updated: 2008-07-28
Downloads

The VirtualColumn Demo Program has a TNextGrid with a TNxTextualColumn and a TNxVirtualColumn. The demo program is very basic and uses the virtual column to display the length of the text in the textual column.
The OnGetText event handler for the TNxVirtualColumn looks like:
procedure TForm1.LengthColGetText(Sender: TObject; const ACol, ARow: Integer; var Value: WideString); begin with TNextGrid(TNxVirtualColumn(Sender).GridComponent) do if (ARow >= 0) and (ARow < RowCount) then Value := IntToStr(Length(CellByName['TextCol', ARow].AsString)); end;
It simply sets the Value to be displayed to the length of the first column. Note that addressing cells by name and index is used and some checks are made that the cells referenced actually exists.
Next we add a button to add a row to the grid and add some text to its first column.
procedure TForm1.AddBtnClick(Sender: TObject); begin with NextGrid1 do begin AddRow; CellByName['TextCol', 'Last'].AsString := 'The Quick Brown Fox...'; end; TruncateBtn.Enabled := True; end;
Note that after pressing this "Add" Button the second column is automatically updated as well and the code above is executed.

But when you edit the first column the second column isn't updated as the grid can't possibly know the data is updated (because the grid doesn't know where program gets the data from, it also doesn't know that the data is linked to the data of the first textual column).
To correct this behavior we need to tell the grid to update the virtual column as well whenever the first column is changed. The best spot is the OnAfterEdit handler of the first column as that's where the input for the data of the virtual column originates.
So if we add the following event handler code:
procedure TForm1.NextGrid1AfterEdit(Sender: TObject; ACol, ARow: Integer; Value: WideString); begin with TNextGrid(Sender) do Columns.Column['LengthCol'].Refresh(gaBody); end;
The grid will update the virtual column whenever the first column (of which the length is displayed in the virtual column) is changed after the used is finished with editing it.

The grid will update the virtual column whenever the first column (of which the length is displayed in the virtual column) is changed after the used is finished with editing it.
A last feature of the TNxVirtualColumn is the OnSetText event handler. It is fired whenever the text of the virtual column is set by the program. When for instance the following OnSetText event handler code is added, and the truncate button is pressed to set the value of the virtual columns first row to 10, the text of the textual column is truncated to 10 characters.