New to Telerik UI for WinForms? Download free 30-day trial

Working with Content Controls

This article shows some examples of how you can access a content control and modify their properties from the code. In general, the content controls are marked with annotations and you can manipulate them as such. Detailed information is available here: Manipulating Annotations

Manipulate existing content controls

Get the content controls.

The content controls can be retrieved by using the GetAnnotationMarkersOfType method. This is demonstrated in the following example.

Example 1: Get all Content Controls

IEnumerable<SdtRangeStart> content_controls = this.radRichTextEditor1.Document.GetAnnotationMarkersOfType<SdtRangeStart>();
foreach (var item in content_controls)
{
    Console.WriteLine("Type: {0} ID:{1}", item.SdtProperties.Type, item.SdtProperties.ID);
}

Dim content_controls As IEnumerable(Of SdtRangeStart) =
    Me.RadRichTextEditor1.Document.GetAnnotationMarkersOfType(Of SdtRangeStart)()
For Each item In content_controls
    Console.WriteLine("Type: {0} ID:{1}", item.SdtProperties.Type, item.SdtProperties.ID)
Next

Set content controls properties.

This example shows how you can iterate the items and add an item to a existing ComboBox content control.

Example 2: Adding items to a ComboBox or a DropDownList

foreach (var item in content_controls)
{
    if (item.SdtProperties.Type == SdtType.ComboBox)
    {
        ComboBoxProperties properties = item.SdtProperties as ComboBoxProperties;
        ListItem newItem = new ListItem();
        newItem.DisplayText = "New Item Text";
        properties.Items.Add(newItem);
    }
}

For Each item In content_controls
    If item.SdtProperties.Type = SdtType.ComboBox Then
        Dim properties As ComboBoxProperties = TryCast(item.SdtProperties, ComboBoxProperties)
        Dim newItem As New ListItem()
        newItem.DisplayText = "New Item Text"
        properties.Items.Add(newItem)
    End If
Next

Insert new content controls

New content controls can be inserted trough one of the overloads of the InsertStructuredDocumentTag method accessible from RadRichTextEditor and RadDocumentEditor:

Example 3: Inserting a content control

this.radRichTextEditor1.InsertStructuredDocumentTag();
// OR 
RadDocumentEditor editor = new RadDocumentEditor(this.radRichTextEditor1.Document);
editor.InsertStructuredDocumentTag();

Me.RadRichTextEditor1.InsertStructuredDocumentTag()
'OR
Dim editor As RadDocumentEditor = New RadDocumentEditor(Me.RadRichTextEditor1.Document)
editor.InsertStructuredDocumentTag()

Example 4: Inserting a content control using content control type

this.radRichTextEditor1.InsertStructuredDocumentTag(SdtType.CheckBox);
// OR 
RadDocumentEditor editor = new RadDocumentEditor(this.radRichTextEditor1.Document);
editor.InsertStructuredDocumentTag(SdtType.CheckBox);

Me.RadRichTextEditor1.InsertStructuredDocumentTag(SdtType.CheckBox)
'OR
Dim editor As RadDocumentEditor = New RadDocumentEditor(Me.RadRichTextEditor1.Document)
editor.InsertStructuredDocumentTag(SdtType.CheckBox)

Example 5: Inserting a content control using content control properties

SdtProperties sdtProperties = new SdtProperties(SdtType.RichText)
{
    Alias = "AliasName",
    Lock = Lock.SdtContentLocked,
};
this.radRichTextEditor1.InsertStructuredDocumentTag(sdtProperties);
// OR 
RadDocumentEditor editor = new RadDocumentEditor(this.radRichTextEditor1.Document);
editor.InsertStructuredDocumentTag(sdtProperties);

Dim sdtProperties As SdtProperties = New SdtProperties(SdtType.RichText) With {
.Alias = "AliasName",
.Lock = Lock.SdtContentLocked
 }
Me.RadRichTextEditor1.InsertStructuredDocumentTag(sdtProperties)
'OR
Dim editor As RadDocumentEditor = New RadDocumentEditor(Me.RadRichTextEditor1.Document)
editor.InsertStructuredDocumentTag(sdtProperties)

See Also

In this article
Not finding the help you need? Improve this article