共用方式為


DropDownListContentControl.DropDownListEntries 屬性 (2007 系統)

更新: 2008 年 7 月

取得 DropDownListContentControl 所顯示的項目集合。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word.v9.0 (在 Microsoft.Office.Tools.Word.v9.0.dll 中)

語法

<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 DropDownListContentControl
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; }

屬性值

型別:Microsoft.Office.Interop.Word.ContentControlListEntries

ContentControlListEntries 物件,包含 DropDownListContentControl 所顯示的項目。

備註

當您在文件上加入 DropDownListContentControl 控制項時,依照預設它不包含任何項目。若要加入項目,請使用 DropDownListEntries 屬性的 Add 方法。

範例

下列程式碼範例會將新的 DropDownListContentControl 加入至文件的開頭。這個範例會使用 DropDownListEntries 屬性,將幾個日期名稱加入至使用者可用控制項選取的項目清單。

這是示範文件層級自訂的版本。若要使用這段程式碼,請將它貼到專案的 ThisDocument 類別中,並從 ThisDocument_Startup 方法呼叫 AddDropDownListControlAtSelection 方法。

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";
}

這是示範應用程式層級增益集的版本。若要使用這段程式碼,請將它貼到專案的 ThisAddIn 類別中,並從 ThisAddIn_Startup 方法呼叫 AddDropDownListControlAtSelection 方法。

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 = Me.Application.ActiveDocument.GetVstoObject()
    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 = this.Application.ActiveDocument.GetVstoObject();
    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";
}

使用權限

請參閱

參考

DropDownListContentControl 類別

DropDownListContentControl 成員

Microsoft.Office.Tools.Word 命名空間

變更記錄

日期

記錄

原因

2008 年 7 月

加入應用程式層級增益集的程式碼範例版本。

SP1 功能變更。