Skip to main content
All docs
V25.1
  • DevExpress v25.1 Update — Your Feedback Matters

    Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

    Take the survey Not interested

    ContentControlDate Interface

    Date picker content control.

    Namespace: DevExpress.XtraRichEdit.API.Native

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

    NuGet Package: DevExpress.RichEdit.Core

    #Declaration

    public interface ContentControlDate :
        ContentControlBase

    The following members return ContentControlDate objects:

    #Remarks

    #Create a Date Picker Content Control

    The code sample below creates a date picker control:

    date picker in word processing

    using DevExpress.XtraRichEdit;
    using DevExpress.XtraRichEdit.API.Native;
    
    using (var wordProcessor = new RichEditDocumentServer()){
    
        wordProcessor.CreateNewDocument();
        Document document = wordProcessor.Document;
        var contentControls = document.ContentControls;
    
        var datePicker = contentControls.InsertDatePickerControl(document.Range.Start);
        datePicker.Date = DateTime.Now;
        datePicker.DateFormat = "dddd, MMMM dd, yyyy";
        datePicker.Color = System.Drawing.Color.RebeccaPurple;
        wordProcessor.SaveDocument("Content Controls Date Picker.docx", DocumentFormat.Docx);
    
        Process.Start(new ProcessStartInfo("Content Controls Date Picker.docx") { UseShellExecute = true });
    }
    

    #Access Date Picker 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 date pickers 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 datePickers = document.ContentControls.Where(contentControl => contentControl.ControlType == ContentControlType.Date).Cast<ContentControlDate>();
    
        foreach ( ContentControlDate datePicker in datePickers )
        {
            // your code here
        }
    

    #Modify Check Box Content Controls

    Use the ContentControlDate class properties to change the date picker parameters. The code sample below retrieves the date picker from the first paragraph and changes its date format:

    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.Date) {
              ContentControlDate datePicker = (ContentControlDate)contentControls[i];
    
              datePicker.DateFormat = "d MMMM yyyy";
              break;
          }
          wordProcessor.SaveDocument("Content Controls.docx", DocumentFormat.Docx);
      }
    }
    

    #Remove Check 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 date pickers 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.Date)
            {
                contentControls.Remove(contentControls[i], true);
            }
        }
    }
    
    See Also