This example demonstrates how to implement a custom "Insert Document Field" dialog to insert fields with corresponding formatting attributes into RichEditControl documents.
All fields are inserted into a current document position using the SubDocument.Fields.Create method. The key point here is that you need to obtain a corresponding sub-document which is related to the caret position, since the caret can be located in the main document, its header or footer.
To obtain a corresponding sub-document, the DocumentPosition.BeginUpdateDocument method is used.
Also, this example demonstrates how to insert expressions and results of the "IF" field calculation as nested document fields (there is a corresponding option near the "left expression", "right expression", "true result" and "false result" of the "IF" field attributes).
To built the solution demonstrated in this sample into an existing application, copy all modules and the "insertFieldIcon.png" image located in the InsertFieldModules folder and use a corresponding RegisterInsertFieldDialogCommand extension method to add the "Insert Field" command onto a current Ribbon control:
CS
[C#]richEditControl1.RegisterInsertFieldDialogCommand(ribbonPageGroup1,null);
VB
[VB.NET]richEditControl1.RegisterInsertFieldDialogCommand(ribbonPageGroup1, Nothing)