Partager via


ComboBoxContentControl.DropDownListEntries, propriété (System 2007)

Mise à jour : Juillet 2008

Obtient la collection des éléments affichés par le ComboBoxContentControl.

Espace de noms :  Microsoft.Office.Tools.Word
Assembly :  Microsoft.Office.Tools.Word.v9.0 (dans Microsoft.Office.Tools.Word.v9.0.dll)

Syntaxe

<TypeConverterAttribute("Microsoft.VisualStudio.OfficeTools.Word2007.Design.DropDownListConverter, Microsoft.VisualStudio.Tools.Office.Designer.Office2007, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")> _
Public ReadOnly Property DropDownListEntries As ContentControlListEntries

Dim instance As ComboBoxContentControl
Dim value As ContentControlListEntries

value = instance.DropDownListEntries
[TypeConverterAttribute("Microsoft.VisualStudio.OfficeTools.Word2007.Design.DropDownListConverter, Microsoft.VisualStudio.Tools.Office.Designer.Office2007, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public ContentControlListEntries DropDownListEntries { get; }

Valeur de propriété

Type : Microsoft.Office.Interop.Word.ContentControlListEntries

Objet ContentControlListEntries qui contient les éléments affichés par le ComboBoxContentControl.

Notes

Lorsque vous ajoutez un ComboBoxContentControl à un document, par défaut, il ne contient aucun élément. Pour ajouter des éléments, utilisez la méthode Add de la propriété DropDownListEntries.

Exemples

L'exemple de code suivant ajoute un nouveau ComboBoxContentControl au début du document. Les utilisateurs peuvent choisir un nom de couleur affiché par le contrôle ou bien taper le nom d'une nouvelle couleur. Cet exemple utilise la propriété DropDownListEntries pour spécifier les noms de couleurs affichés par le contrôle.

Cette version est destinée à une personnalisation au niveau du document. Pour utiliser ce code, collez-le dans la classe ThisDocument de votre projet, puis appelez la méthode AddComboBoxControlAtSelection à partir de la méthode ThisDocument_Startup.

Dim comboBoxControl1 As Microsoft.Office.Tools.Word.ComboBoxContentControl

Private Sub AddComboBoxControlAtSelection()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Select()
    comboBoxControl1 = Me.Controls.AddComboBoxContentControl("comboBoxControl1")
    With comboBoxControl1
        .DropDownListEntries.Add("Red", "Red", 0)
        .DropDownListEntries.Add("Green", "Green", 1)
        .DropDownListEntries.Add("Blue", "Blue", 2)
        .PlaceholderText = "Choose a color, or enter your own"
    End With
End Sub
private Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl1;

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

    comboBoxControl1 = this.Controls.AddComboBoxContentControl("comboBoxControl1");
    comboBoxControl1.DropDownListEntries.Add("Red", "Red", 0);
    comboBoxControl1.DropDownListEntries.Add("Green", "Green", 1);
    comboBoxControl1.DropDownListEntries.Add("Blue", "Blue", 2);
    comboBoxControl1.PlaceholderText = "Choose a color, or enter your own";
}

Cette version est destinée à un complément d'application. Pour utiliser ce code, collez-le dans la classe ThisAddIn de votre projet, puis appelez la méthode AddComboBoxControlAtSelection à partir de la méthode ThisAddIn_Startup.

Dim comboBoxControl1 As Microsoft.Office.Tools.Word.ComboBoxContentControl

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

    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
    vstoDoc.Paragraphs(1).Range.Select()
    comboBoxControl1 = vstoDoc.Controls.AddComboBoxContentControl("comboBoxControl1")
    With comboBoxControl1
        .DropDownListEntries.Add("Red", "Red", 0)
        .DropDownListEntries.Add("Green", "Green", 1)
        .DropDownListEntries.Add("Blue", "Blue", 2)
        .PlaceholderText = "Choose a color, or enter your own"
    End With
End Sub
private Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl1;

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

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

    comboBoxControl1 = vstoDoc.Controls.AddComboBoxContentControl(
        "comboBoxControl1");
    comboBoxControl1.DropDownListEntries.Add("Red", "Red", 0);
    comboBoxControl1.DropDownListEntries.Add("Green", "Green", 1);
    comboBoxControl1.DropDownListEntries.Add("Blue", "Blue", 2);
    comboBoxControl1.PlaceholderText = "Choose a color, or enter your own";            
}

Autorisations

Voir aussi

Référence

ComboBoxContentControl, classe

Membres ComboBoxContentControl

Microsoft.Office.Tools.Word, espace de noms

Historique des modifications

Date

Historique

Raison

Juillet 2008

Ajout d'une version de l'exemple de code pour un complément d'application.

Modifications de fonctionnalités dans le SP1.