NewDropdownCombo

Description

Adds a combobox control with a 'Dropdown Combo' style to a form. This style includes both a dropdown list and a text box. The user can select from the list or type in the text box.
The items in the list will not be sorted automatically.

Syntax

[Set oCtl =] oFrm.NewDropdownCombo

( 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 dropdowncombo. 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

BackColor

Background color (use the RGB function to assign a color value)

Enabled

(boolean) Determines if the control can respond to user-generated events

Fontname

The font used to display text. The default is determined by the system. Check the glossary for an explanation about setting font properties.

Fontsize

The size of the font in points. The maximum is 2160 points.

Fontbold

(boolean) Enable or disable the bold style of a font

Fontitalic

(boolean) Enable or disable the italic style of a font

Fontstrikethru

(boolean) Enable or disable the strikethru style of a font

Fontunderline

(boolean) Enable or disable the underline style of a font

ForeColor

Foreground color (use the RGB function to assign a color value)

Height

(read-only) The height of the control in twips

IntegralHeight

(read-only) The control resizes to display only complete items.

ItemData

(long integer) A specific number associated with an item in the list. You can use these numbers to further identify the items. For example, you can use an employee's identification number to identify each employee name.

Note : When you insert an item with the AddItem method, the ItemData value isn't reinitialized to zero; it retains the value that was in that position before you added the item. When you use the ItemData property, be sure to set its value when adding new items to a list.

Left

The distance from the left edge of the specified container in twips

List (index)

(string) The text of an item in the list at the specified index. The first item has index 0 and the index of the last item is ListCount – 1.

ListCount

(read-only) The total number of items in the list

ListIndex

(integer) Returns or sets the index of the currently selected item in the list

-1

(default) Indicates no item is currently selected or the user has entered new text into the text box portion

n

A number indicating the index of the currently selected item. The index of the first item is 0 and the index of the last item is ListCount – 1

Locked

(boolean) Determines whether the control can be edited (default) or not

NewIndex

(read-only) The index of the item most recently added. Returns -1 if there are no items or if an item was deleted since the last item was added.

Parent

(read-only) Returns the parent form, object or collection. You can use the parent property to access the properties and methods of an object's parent

Sorted

(read-only) Indicates whether the items are automatically sorted or not

Style

(read-only) Returns 0 to indicate that the control is a dropdown combo which includes both a dropdown list and a text box

TabStop

(boolean) Determines whether the TAB key can be used to move the focus

Tag

(reserved) Used internally to store the user-defined controlname

Text

(read-only) The text contained in the edit area of the control

ToolTipText

Explanatory text that appears in a small rectangle below the object when you pause the mouse pointer (hover) over it for about one second

Top

The distance from the top edge of the specified container in twips

TopIndex

(integer) The index of the item displayed in the topmost position

Visible

(boolean) Determines whether the control is visible or hidden

Width

The width of the control in twips

Method

Description

AddItem

Parameters : item [, index ]

item

(string) The item to be added to the the list

index

(integer) The position in the list where the new item is placed. If index is omitted, the item is added to the end of the list

Clear

Clears all the items in the list

Move

Parameters: left [, top [, width ]]

Only the left argument is required. However, to specify any other arguments, you must specify all arguments that appear in the syntax before the argument you want to specify. For example, you can't specify width without specifying left and top. Any trailing arguments that are unspecified remain unchanged

Refresh

Forces a complete repaint of a control

RemoveItem

Parameter : index

Removes the item at the specified index from the list

SetFocus

Moves the focus to the specified control

Event

Description

Event raised

Click

Occurs when the user selects an item with the left mouse button or the UP, DOWN, PGUP or PGDN keys

Controlname

To be able to handle events you need to operate a form in callback mode.
This subject is described in the following topics:
Callback forms, ClickHandler

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 dropdowncombo control named DDC1 to the oFrm form
'and store a reference to the DDC1 control in the variable oCtl
Set oCtl = oFrm.NewDropdownCombo("DDC1", 150, 150, 2500)

'Use the reference variable to add some items to the dropdown
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("DDC1") & " (index " & oFrm.Ctl("DDC1").ListIndex & ") was selected"
End If