The main idea of this example is to create a custom form with RichEditControl inside and show this form instead of SpreadsheetControl's built-in in-place editor to edit a cell's rich text using the RichEditControl component's facilities. In this example, the custom edit form is shown in an attempt to open an in-place editor for cells with rich text (it's invoked in the CellBeginEdit event handler). Also, it is possible to show this form by clicking the “Set Rich Text” context menu item.
It's necessary to solve two tasks at the custom form's level to make it edit the cell's rich text:
- Load and show the cell's rich text in RichEditControl when an end-user opens a custom form.
- Post changes from RichEditControl to the Spreadsheet cell once the user finishes editing rich text and closes the form.
The solution for the first task is to transform the cell's rich text from the Spreadsheet model to the RichEdit document model. Split cell rich text into runs (text parts with unique formatting) using the Spreadsheet API, look through the run collection, and build a document using the RichEdit API:
- Append each run's text to the RichEditControl document;
- Create CharacterProperties based on run font settings;
- Apply character properties to the inserted text part
Now the user can edit the rich text in RichEditControl using the Bars UI.
To submit changes on form closing, transform RichEditControl's model back to the Spreadsheet model and build a new Spreadsheet cell value as follows:
- Split the RichEditControl document into text runs using a custom Document Visitor class;
- Transform each text run into a Spreadsheet RichTextRun object;
- Combine all RichTextRun objects into RichTextString;
- Assign RichTextString as a cell value using the Range.SetRichText method.
C# | Visual Basic |
---|---|
Form1.cs | Form1.vb |
RichTextEditForm.cs | RichTextEditForm.vb |
CustomDocumentVisitor.cs | CustomDocumentVisitor.vb |
How to: Apply Rich Formatting to Cell Text
- How to: Apply Rich Formatting to Cell Text
- How to: Retrieve the List of Document Fonts using the Visitor-Iterator Pattern
(you will be redirected to DevExpress.com to submit your response)