Using drop-down lists

Drop-down lists are another way to present simple lists of information to the user. You can present your lists with just text (in a DropDownListBox) or with text and pictures (in a DropDownPictureListBox). You add DropDownListBox and DropDownPictureListBox controls to windows in the same way you add other controls: select DropDownListBox or DropDownPictureListBox from the Insert>Control menu and click the window.

Adding items to drop-down list controls

In the painter

Use the Items property page for the control to add items.

To add items to a DropDownListBox or DropDownPictureListBox:

  1. Select the Items tab in the Properties view for the control.

  2. Enter the name of the items for the ListBox. For a PictureListBox, also enter a picture index number to associate the item with a picture.

    For how to add pictures to a DropDownPictureListBox, see Adding pictures to DropDownPicture ListBox controls.

In a script

Use the AddItem and InsertItem functions to dynamically add items to a DropDownListBox or DropDownPictureListBox at runtime.

AddItem adds items to the end of the list. However, if the list is sorted, the item will then be moved to its position in the sort order. Use InsertItem if you want to specify where in the list the item will be inserted.

Function

You supply

InsertItem

Item name

Picture index (for a DropDownPictureListBox)

Position in which the item will be inserted

AddItem

Item name

Picture index (for a DropDownPictureListBox)


This example inserts three items into a DropDownPictureListBox in the first, second, and third positions:

This.InsertItem ("Atropos", 2, 1)
This.InsertItem ("Clotho", 2, 2)
This.InsertItem ("Lachesis", 2, 3)

This example adds two items to a DropDownPictureListBox:

this.AddItem ("Plasma", 2)
this.AddItem ("Platelet", 2)

Using the Sort property

You can set the control's sort property to TRUE to ensure that the items in the list are always arranged in ascending sort order.

Adding pictures to DropDownPicture ListBox controls

In the painter

Use the Pictures and Items property pages for the control to add pictures.

To add pictures to a DropDownPictureListBox:

  1. Select the Pictures tab in the Properties view for the control.

  2. Select an image from the stock image list, or use the Browse button to select a bitmap, cursor, or icon image.

  3. Select a color from the PictureMaskColor drop-down menu for the image.

    The color selected for the picture mask will appear transparent in the DropDownPictureListBox.

  4. Select a picture height and width for your image.

    This will control the size of the image in the DropDownPictureListBox.

    Dynamically changing image size

    The image size can be changed at runtime by setting the PictureHeight and PictureWidth properties before you add any pictures when you create a DropDownPictureListBox. For more information about PictureHeight and PictureWidth, see the section called “PictureHeight” in Objects and Controls and the section called “PictureWidth” in Objects and Controls.

  5. Repeat the procedure for the number of images you plan to use in your DropDownPictureListBox.

  6. Select the Items tab and change the Picture Index for each item to the appropriate number.

In a script

Use the AddPicture function to dynamically add pictures to a PictureListBox at runtime. For instance, this example adds two BMP files to the PictureListBox:

This.AddPicture ("c:\images\justify.bmp")
This.AddPicture ("c:\images\center.bmp")

Deleting pictures from DropDownPicture ListBox controls

For instructions on deleting pictures from DropDownPictureListBox controls, see Deleting pictures from picture list controls.