Frequently Asked Component Specific Questions

Options

Display all FAQ items

Search FAQ items:


Displaying items 1 to 1 of 1, page 1 of 1

<< previous next >>

TMS FNC UI Pack
TTMSFNCGrid: Using a TTMSFNCRichEditor as inplace editor for the TTMSFNCGrid

It’s quite straightforward to use the TTMSFNCRichEditor as inplace editor for the grid. In the grid cell, you can display HTML formatted text and this can then be wysiwyg edited with TTMSFNCRichEditor.

All that is needed is to implement a few event handlers. Via OnGetCellEditorType, it is defined that a custom inplace editor should be used:

procedure TForm5.TMSFNCGrid1GetCellEditorType(Sender: TObject; ACol,
  ARow: Integer; var CellEditorType: TTMSFNCGridEditorType);
begin
  CellEditorType:= etCustom;
end;
Next, via the OnGetCellEditorCustomClassType, it is specified that the class to use for the custom editor is TTMSFNCRichEditor:

procedure TForm5.TMSFNCGrid1GetCellEditorCustomClassType(Sender: TObject; ACol,
  ARow: Integer; var CellEditorCustomClassType: TTMSFNCGridEditorClass);
begin
  CellEditorCustomClassType := TTMSFNCRichEditor;
end;
As an extra, a TMSFNCRichEditorFormatToolBar is associated with the TTMSFNCRichEditor when it is active for editing a cell and this is done from the OnGetCellEditorProperties:

procedure TForm5.TMSFNCGrid1GetCellEditorProperties(Sender: TObject; ACol,
  ARow: Integer; CellEditor: TWinControl);
begin
  TMSFNCRichEditorFormatToolBar1.RichEditor := (CellEditor as TTMSFNCRichEditor);
end;
Finally, we must provide the event handlers for OnCellEditGetData and OnCellEditSetData where the cell text is loaded as HTML in the TTMSFNCRichEditor and vice versa. A non-visual TMSFNCRichEditorHTMLIO component is used for this conversion.

procedure TForm5.TMSFNCGrid1CellEditGetData(Sender: TObject; ACol,
  ARow: Integer; CellEditor: TWinControl; var CellString: string);
begin
  TMSFNCRichEditorHTMLIO1.RichEditor := (CellEditor as TTMSFNCRichEditor);
  TMSFNCRichEditorHTMLIO1.LoadHTML(CellString);
end;

procedure TForm5.TMSFNCGrid1CellEditSetData(Sender: TObject; ACol,
  ARow: Integer; CellEditor: TWinControl; var CellString: string);
begin
  CellString := (CellEditor as TTMSFNCRichEditor).ContentAsHTML('''');
end;
The full sample can be downloaded from: https://download.tmssoftware.com/download/GridRichEditorEditor.zip