Skip to content

Edit a cell's rich text using the RichEditControl component's facilities.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/winforms-spreadsheet-how-to-edit-rich-text

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinForms Spreadsheet Control - How to Edit Rich Text in SpreadsheetControl

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.

Implementation Details

It's necessary to solve two tasks at the custom form's level to make it edit the cell's rich text:

  1. Load and show the cell's rich text in RichEditControl when an end-user opens a custom form.
  2. 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:

Files to Review

C# Visual Basic
Form1.cs Form1.vb
RichTextEditForm.cs RichTextEditForm.vb
CustomDocumentVisitor.cs CustomDocumentVisitor.vb

More Examples

How to: Apply Rich Formatting to Cell Text

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)