Synergy: Working with a combobox
Vendredi 19 Juin 2009 at 4:14 pm. Balises utilisées: dynacom, synergyThis article covers how to interact with a combobox or if you prefer a DynaDropdownList.
Note: The links referenced in this article are about Visual Basic 6 but can easily apply to VBScript.
Properties
| Property | Data Type | Description | Reference |
| Appearance | Long | Returns or sets the paint style of controls on an MDIForm or Form object at design time. Read-only at run time. | Appearance Property |
| BackColor | Long | BackColor returns or sets the background color of an object. | BackColor, ForeColor Properties |
| Control | Object | ||
| DataBoundInterface | DynaDropdownList | ||
| Enabled | Boolean | Returns or sets a value that determines whether a form or control can respond to user-generated events. | Enabled Property |
| Font | Font | Returns a Font object. | Font Property |
| ForeColor | Long | BackColor returns or sets the background color of an object. | BackColor, ForeColor Properties |
| ItemData | Long | Returns or sets a specific number for each item in a ComboBox or ListBox control. | ItemData Property |
| List | String | Returns or sets the items contained in a control's list portion. | List Property |
| ListCount | Integer | Returns the number of items in the list portion of a control. | ListCount Property |
| ListIndex | Integer | Returns or sets the index of the currently selected item in the control. Not available at design time. | ListIndex Property |
| Locked | Boolean | Returns or sets a value indicating whether a control can be edited. | Locked Property |
| MouseIcon | Picture | Returns or sets a custom mouse icon. | MouseIcon Property |
| MousePointer | Long | Returns or sets a value indicating the type of mouse pointer displayed when the mouse is over a particular part of an object at run time. | MousePointer Property |
| NewIndex | Integer | Returns the index of the item most recently added to a ComboBox or ListBox control. Read only at run time. | NewIndex Property |
| Sorted | Boolean | Returns a value indicating whether the elements of a control are automatically sorted alphabetically. | Sorted Property |
| ToolTipText | String | Returns or sets a ToolTip. | ToolTipText Property |
| ValueRequired | Boolean |
Methods
| Method | Parameters | Description | Reference |
| AddItem | item: Required. string expression specifying the item to add to the object. | Adds an item to a ListBox or ComboBox control | AddItem Method |
| RemoveItem | index: Required. Integer representing the position within the object of the item remove. | Removes an item from a ListBox or ComboBox control | RemoveItem Method |
| Clear | None | Clears the contents of a ListBox or ComboBox | Clear Method |
Examples
Adding an item
Controls("cboItems").Object.Control.AddItem "Item 1"
Removing an item
Controls("cboItems").Object.Control.RemoveItem 1
Clear a combobox
Controls("cboItems").Object.Control.Clear
Retrieve the selected item
Controls("cboItems").Object.List(Controls("cboItems")
.Object.ListIndex)
Loop through all items
'Declare local variables
Dim intItemIndex 'As Integer
Dim cboItems 'As DynaDropdownList
Dim i 'As Integer
'Initialize local variables
intItemIndex = -1
Set cboItems = Controls("cboItems").Object
'Find a specific item
For i = 0 To cboItems.ListCount - 1
If cboItems.List(i) = "Item 1" Then
intItemIndex = i
End If
Next
'If item is not in the combobox, add it
If intItemIndex = -1 Then
cboItems.AddItem "Item 1"
ElseIf intItemIndex > -1 Then
cboItems.RemoveItem intItemIndex
End If
Pas de commentaire