Example 8 : RTF display capabilities

vcl grid RTF

This project is a simple application that shows the RTF display capabilities of TAdvStringGrid. As input for this demo, an Excel like approach is chosen, where a single editor sets the text for each cell. Two methods are available to transfer rich text to and from a rich edit control:

procedure CellToRich(acol,arow:integer;arichedit:trichedit);
This method, transfers the text from cell [acol,arow] to the arichedit edit control.

procedure RichToCell(acol,arow:integer;arichedit:trichedit);
This is the inverse method that transfers the text back from the rich edit control to the grid at cell acol,arow.

These two methods are used to connect the rich edit control to the grid. In the OnSelectCell event handler, text from the selected cell is transfered to the edit control, while the OnClick event handler of the update speedbutton transfers the current rich edit content back to the selected cell.

Rich text as well as not rich text can be mixed in the grid. The grid automatically detects if the cell contains rich edit text or not. To update a cell with non rich text; simply use the normal approach:

TAdvStringGrid.Cells[ACol,ARow] := "Test";
To retrieve the text of a cell without the rich formatting added, first transfer the cell contents to a richedit control and access it with its Text property :

  s := richedit1.text;

Finally, full rich formatting can be saved as well to CSV files or being loaded from CSV files. Make sure though the MultiLineCells property is set true.

Delphi project & source files for downloading included in the main demos distribution for Delphi.