NewDropdownList

Description

Adds a combobox control with a 'Dropdown List' style to a form. This style only has a dropdown list and does not include a text box as the 'Dropdown Combo' style does.

Syntax

[Set oCtl =] oFrm.NewDropdownList

( Name, Left, Top, Width, [Container] )

Parameters

Part

Description

Set oCtl =

(optional) Store a reference to the new control in the variable oCtl. This variable can be used to access the control's properties and methods.

oFrm

A reference to a form object (see the NewForm method)

Name

The name of the control. It must be unique within the form and may not be empty or start with an asterisk (*)

Left

See the list of properties below

Top

See the list of properties below

Width

See the list of properties below

Container

(optional) The name of an existing frame control that will act as container for the dropdownlist. If unspecified or an empty string, the Form itself will be the container. Please note that the Left and Top properties are relative to the container's left and top edges

Properties, Methods and Events

Property

Description

Style

(read-only) Returns 2 to indicate that the control is a dropdown list

Text

(read-only) The currently selected item. Equivalent to List(ListIndex)

<all others>

See the DropDownCombo page. Because both a Dropdown List and a Dropdown Combo are Combobox controls,only the few properties that differ from a Dropdown Combo are listed above !

Methods

Events

Example

Option Explicit

Const vbModal = 1

Dim oDlg, oFrm, oCtl

'Create the WshDialog.Kit object and store a reference in oDlg
Set oDlg = Wscript.CreateObject("WshDialog.Kit", "oDlg_")

'Add a new form and store a reference to it in the variable oFrm
Set oFrm = oDlg.NewForm("Sample")

'Add a dropdown list control named DDL1 to the oFrm form
'and store a reference to the DDL1 control in the variable oCtl
Set oCtl = oFrm.NewDropdownList("DDL1", 150, 150, 2500)

'Use the reference variable to add some items to the dropdown list
oCtl.AddItem "The first item"
oCtl.AddItem "The second item"
oCtl.AddItem "The third item"

'Make the first item (with index 0) the currently selected item
oCtl.ListIndex = 0

'Add an OK button and set it's Default property
Set oCtl = oFrm.NewButton("OK", 900, 1250, 1000, 375, "&OK")
oCtl.Default = True

'Automatically size the form and show it (modally)
oFrm.Autosize
oFrm.Show vbModal

'Show which item was selected (only if the OK button was clicked)
If oDlg.Clicked = "OK" Then
    MsgBox oFrm.Ctl("DDL1") & " (index " & oFrm.Ctl("DDL1").ListIndex & ") was selected"
End If