TAdvStringGrid

Example: Using TAdvRichEditor as inplace editor in the grid

vcl grid editing

vcl grid editing


It doesn't take more than three (3!) lines of code to enable editing in a grid cell with a TAdvRichEditor and use either an always visible format toolbar or a popup quick format toolbar.

To get started, drop a TAdvStringGrid, TAdvRichEditorEditLink and a TAdvRichEditorFormatToolBar control on the form. To enable editing in the grid with the TAdvRichEditor, the grid is initalized with:
procedure TForm1.FormCreate(Sender: TObject);
begin
  AdvStringGrid1.Options := AdvStringGrid1.Options + [goEditing];
  AdvStringGrid1.DefaultEditor := edCustom;
  AdvStringGrid1.EditLink := AdvRichEditorEditLink1;
end;
The only thing left to do is link up the TAdvRichEditorFormatToolBar with the correct inplace TAdvRichEditor when the cell is being edited so the settings on the format toolbar reflect the settings of this specific cell editor. To do this, the grid.OnGetEditorProp() event is implemented. This event is triggered after the cell inplace editor is made visible in the cell and ready for use. Thus, in this event, the instance of TAdvRichEditor can be retrieved from the TAdvRichEditorEditLink and linked up with the format toolbar:
procedure TForm1.AdvStringGrid1GetEditorProp(Sender: TObject; ACol,
  ARow: Integer; AEditLink: TEditLink);
begin
  AdvRichEditorFormatToolBar1.RichEditor :=  AdvRichEditorEditLink1.RichEditor;
end;
The TAdvRichEditorEditLink offers also a capability to have a popup toolbar that appears over a selection in the TAdvRichEditor for quick formatting of the selected text. This is controlled by the property TAdvRichEditorEditLink.PopupToolbar: boolean; To further finish this sample, a checkbox was added on the form from where the user can toggle between the always visible format toolbar or the popup toolbar:
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if checkbox1.checked then
  begin
    AdvRichEditorEditLink1.PopupToolbar := true;
    AdvRichEditorFormatToolBar1.Visible := false;
    CheckBox1.Caption := 'Always visible toolbar';
  end
  else
  begin
    AdvRichEditorEditLink1.PopupToolbar := false;
    AdvRichEditorFormatToolBar1.Visible := true;
    CheckBox1.Caption := 'Popup toolbar (select text and hover over selected text)';
  end;
end;