Back to Devexpress

ContentControlDropDownList Interface

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-391799dd.md

latest7.9 KB
Original Source

ContentControlDropDownList Interface

Drop-down list content control.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
public interface ContentControlDropDownList :
    ContentControlListBase,
    ContentControlBase
vb
Public Interface ContentControlDropDownList
    Inherits ContentControlListBase,
             ContentControlBase

The following members return ContentControlDropDownList objects:

Remarks

Create a Drop-Down List Content Control

The code sample below creates a drop down list content controls:

image

csharp
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

using (var wordProcessor = new RichEditDocumentServer()) {
    Document document = wordProcessor.Document;
    var contentControls = document.ContentControls;

    // Insert a drop-down list to select the appointment type:
    var listPosition = document.CreatePosition(document.Paragraphs[2].Range.End.ToInt() - 1);
    var listControl = contentControls.InsertDropDownListControl(listPosition);

    // Add items to the drop-down list:
    listControl.AddItem("First Appointment", "First Appointment");
    listControl.AddItem("Follow-Up Appointment", "Follow-Up Appointment");
    listControl.AddItem("Laboratory Results Check", "Laboratory Results Check");

    listControl.SelectedItemIndex = 1;
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native

Using wordProcessor = New RichEditDocumentServer()
    Dim document As Document = wordProcessor.Document
    Dim contentControls = document.ContentControls

    ' Insert a drop-down list to select the appointment type:
    Dim listPosition = document.CreatePosition(document.Paragraphs(2).Range.End.ToInt() - 1)
    Dim listControl = contentControls.InsertDropDownListControl(listPosition)

    ' Add items to the drop-down list:
    listControl.AddItem("First Appointment", "First Appointment")
    listControl.AddItem("Follow-Up Appointment", "Follow-Up Appointment")
    listControl.AddItem("Laboratory Results Check", "Laboratory Results Check")

    listControl.SelectedItemIndex = 1

End Using

Access Drop-Down List 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 drop-down lists in a document:

csharp
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

using (var wordProcessor = new RichEditDocumentServer()) {

    Document document = wordProcessor.Document;
    var contentControls = document.ContentControls;

    var lists = document.ContentControls.Where(contentControl => contentControl.ControlType == ContentControlType.DropDownList).Cast<ContentControlDropDownList>();

    foreach (ContentControlDropDownList list in lists)
    {
        // your code here
    }
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native

Using wordProcessor = New RichEditDocumentServer()

  Dim document As Document = wordProcessor.Document
  Dim contentControls = document.ContentControls

  Dim comboBoxes = document.ContentControls.Where(Function(contentControl) contentControl.ControlType = ContentControlType.DropDownList).Cast(Of ContentControlDropDownList)()

  For Each list In lists
    ' your code here
  Next list

Modify Drop-Down List Content Controls

Use the ContentControlDropDownList class properties to change the drop-down list parameters. The code sample below retrieves the drop-down list from the first paragraph and changes its border color:

csharp
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.DropDownList)
        {
            ContentControlDropDownList list = (ContentControlDropDownList)contentControls[i];

            list.Color = Color.Crimson;
            break;
        }
        wordProcessor.SaveDocument("Content Controls.docx", DocumentFormat.Docx);
    }
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native

Using wordProcessor = New RichEditDocumentServer()

  wordProcessor.LoadDocument("Content Controls.docx")
  Dim document As Document = wordProcessor.Document
  Dim contentControls = document.ContentControls
  Dim firstParagraph = document.Paragraphs(0)
  For i = 0 To contentControls.Count - 1
    If firstParagraph.Range.Contains(contentControls(i).Range.Start) AndAlso contentControls(i).ControlType = ContentControlType.DropDownList Then
      Dim list As ContentControlDropDownList = CType(contentControls(i), ContentControlDropDownList)

      list.Color = Color.Crimson
      Exit For
    End If
    wordProcessor.SaveDocument("Content Controls.docx", DocumentFormat.Docx)
  Next i
End Using

Remove Drop-Down List 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 drop-down lists from the document:

csharp
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.DropDownList)
        {
            contentControls.Remove(contentControls[i], true);
        }
    }
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native

Using wordProcessor = New RichEditDocumentServer()
  Dim document As Document = wordProcessor.Document
  Dim contentControls = document.ContentControls

  Dim i = 0
  Do While i < contentControls.Count
    If contentControls(i).ControlType = ContentControlType.DropDownList Then
      contentControls.Remove(contentControls(i), True)
    End If
    i += 1
  Loop
End Using

See Also

ContentControlDropDownList Members

DevExpress.XtraRichEdit.API.Native Namespace