ControlCollection.AddDropDownListContentControl-Methode (String)

Fügt bei der aktuellen Auswahl im Dokument ein neues DropDownListContentControl hinzu.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

'Declaration
Function AddDropDownListContentControl ( _
    name As String _
) As DropDownListContentControl
DropDownListContentControl AddDropDownListContentControl(
    string name
)

Parameter

Rückgabewert

Typ: Microsoft.Office.Tools.Word.DropDownListContentControl
Das DropDownListContentControl, das dem Dokument hinzugefügt wurde.

Ausnahmen

Ausnahme Bedingung
ArgumentNullException

name ist nullNULL-Verweis (Nothing in Visual Basic) oder hat die Länge 0 (null).

ControlNameAlreadyExistsException

Ein Steuerelement mit dem gleichen Namen ist bereits in der ControlCollection vorhanden.

Hinweise

Verwenden Sie diese Methode, um bei der aktuellen Auswahl im Dokument zur Laufzeit ein neues DropDownListContentControl hinzuzufügen. Weitere Informationen finden Sie unter Hinzufügen von Steuerelementen zu Office-Dokumenten zur Laufzeit.

Beispiele

Im folgenden Codebeispiel wird am Anfang des Dokuments ein neues DropDownListContentControl hinzugefügt. Im Beispiel werden auch die Namen verschiedener Tage zur Liste der Elemente hinzugefügt, die Benutzer im Steuerelement auswählen können.

Diese Version bezieht sich auf eine Anpassung auf Dokumentebene. Zum Verwenden dieses Codes fügen Sie ihn in der ThisDocument-Klasse in das Projekt ein und rufen in der ThisDocument_Startup-Methode die AddDropDownListControlAtSelection-Methode auf.

Dim dropDownListControl1 As Microsoft.Office.Tools.Word.DropDownListContentControl

Private Sub AddDropDownListControlAtSelection()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Select()
    dropDownListControl1 = Me.Controls.AddDropDownListContentControl("dropDownListControl1")
    With dropDownListControl1
        .DropDownListEntries.Add("Monday", "Monday", 0)
        .DropDownListEntries.Add("Tuesday", "Tuesday", 1)
        .DropDownListEntries.Add("Wednesday", "Wednesday", 2)
        .PlaceholderText = "Choose a day"
    End With
End Sub
private Microsoft.Office.Tools.Word.DropDownListContentControl dropDownListControl1;

private void AddDropDownListControlAtSelection()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Select();

    dropDownListControl1 = this.Controls.AddDropDownListContentControl("dropDownListControl1");
    dropDownListControl1.DropDownListEntries.Add("Monday", "Monday", 0);
    dropDownListControl1.DropDownListEntries.Add("Tuesday", "Tuesday", 1);
    dropDownListControl1.DropDownListEntries.Add("Wednesday", "Wednesday", 2);
    dropDownListControl1.PlaceholderText = "Choose a day";
}

Diese Version bezieht sich auf ein Add-In auf Anwendungsebene, das auf .NET Framework 4 abzielt. Wenn Sie diesen Code verwenden möchten, fügen Sie ihn in der ThisAddIn-Klasse im Projekt ein, und rufen Sie die AddDropDownListControlAtSelection-Methode aus der ThisAddIn_Startup-Methode auf.

Dim dropDownListControl1 As Microsoft.Office.Tools.Word.DropDownListContentControl

Private Sub AddDropDownListControlAtSelection()
    If Me.Application.ActiveDocument Is Nothing Then
        Return
    End If

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
    vstoDoc.Paragraphs(1).Range.Select()
    dropDownListControl1 = vstoDoc.Controls.AddDropDownListContentControl("dropDownListControl1")
    With dropDownListControl1
        .DropDownListEntries.Add("Monday", "Monday", 0)
        .DropDownListEntries.Add("Tuesday", "Tuesday", 1)
        .DropDownListEntries.Add("Wednesday", "Wednesday", 2)
        .PlaceholderText = "Choose a day"
    End With
End Sub
private Microsoft.Office.Tools.Word.DropDownListContentControl dropDownListControl1;

private void AddDropDownListControlAtSelection()
{
    if (this.Application.ActiveDocument == null)
        return;

    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
    vstoDoc.Paragraphs[1].Range.Select();

    dropDownListControl1 = vstoDoc.Controls.AddDropDownListContentControl("dropDownListControl1");
    dropDownListControl1.DropDownListEntries.Add("Monday", "Monday", 0);
    dropDownListControl1.DropDownListEntries.Add("Tuesday", "Tuesday", 1);
    dropDownListControl1.DropDownListEntries.Add("Wednesday", "Wednesday", 2);
    dropDownListControl1.PlaceholderText = "Choose a day";
}

.NET Framework-Sicherheit

Siehe auch

Referenz

ControlCollection Schnittstelle

AddDropDownListContentControl-Überladung

Microsoft.Office.Tools.Word-Namespace

Weitere Ressourcen

Hinzufügen von Steuerelementen zu Office-Dokumenten zur Laufzeit

Hilfsmethoden für Hoststeuerelemente

Gewusst wie: Hinzufügen von Inhaltssteuerelementen zu Word-Dokumenten