ContentControlComboBox Interface
Combo box content control.
Namespace: DevExpress.XtraRichEdit.API.Native
Assembly: DevExpress.RichEdit.v24.1.Core.dll
NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation
Declaration
Related API Members
The following members return ContentControlComboBox objects:
Remarks
Create a Combo Box Content Control
The code sample below creates a combo box:
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using (var wordProcessor = new RichEditDocumentServer()) {
Document document = wordProcessor.Document;
var contentControls = document.ContentControls;
var comboBoxPosition = document.CreatePosition(document.Paragraphs[2].Range.End.ToInt() - 1);
var comboBox = contentControls.InsertComboBoxControl(comboBoxPosition);
comboBox.AddItem("First Appointment", "First Appointment");
comboBox.AddItem("Follow-Up Appointment", "Follow-Up Appointment");
comboBox.AddItem("Laboratory Results Check", "Laboratory Results Check");
comboBox.SetText("Click to enter a type");
}
Access Combo Box Content Controls
The SubDocument.ContentControls property returns all content controls in a document. Use the ContentControlBase.ControlType property to determine the content control type.
The code sample below retrieves all combo boxes in a document:
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using (var wordProcessor = new RichEditDocumentServer()) {
Document document = wordProcessor.Document;
var contentControls = document.ContentControls;
var comboBoxes = document.ContentControls.Where(contentControl => contentControl.ControlType == ContentControlType.ComboBox).Cast<ContentControlComboBox>();
foreach (ContentControlComboBox comboBox in comboBoxes)
{
// your code here
}
Modify Combo Box Content Controls
Use the ContentControlComboBox
class properties to change the combo box parameters. The code sample below retrieves the combo box from the first paragraph and changes its border color:
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using (var wordProcessor = new RichEditDocumentServer()) {
wordProcessor.LoadDocument("Content Controls.docx");
Document document = wordProcessor.Document;
var contentControls = document.ContentControls;
var firstParagraph = document.Paragraphs[0];
for (var i = 0; i < contentControls.Count; i++)
{
if (firstParagraph.Range.Contains(contentControls[i].Range.Start) && contentControls[i].ControlType == ContentControlType.ComboBox)
{
ContentControlComboBox comboBox = (ContentControlComboBox)contentControls[i];
comboBox.Color = Color.Crimson;
break;
}
wordProcessor.SaveDocument("Content Controls.docx", DocumentFormat.OpenXml);
}
}
Remove Combo Box Content Controls
The ContentControlCollection.Remove method allows you to remove specific content control. You can also specify whether to keep control’s contents when the controls is removed.
The code sample below removes all combo boxes from the document:
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using (var wordProcessor = new RichEditDocumentServer()) {
Document document = wordProcessor.Document;
var contentControls = document.ContentControls;
for (var i = 0; i < contentControls.Count; i++)
{
if (contentControls[i].ControlType == ContentControlType.ComboBox)
{
contentControls.Remove(contentControls[i], true);
}
}
}