3.6.4. Drop Down List Example

This example shows how the cx-create-drop-down-list, cx-set-list-items, cx-set-list-selections, and cx-show-list-selections macros work. Since both lists and drop-down lists use the same list data type this example is very similar to the example above. The major difference with drop-down lists is that they don’t allow for multiple selections. In the example, both of the drop-down lists are created via cx-create-drop-down-list statements.

Upon opening the dialog box the first drop-down list will automatically load all five list items via a cx-set-list-items line while the second drop-down list starts empty. By selecting one list item from the first drop-down list and then clicking on Button, the selected list item from Drop Down List 1 will be gathered via a cx-show-list-selections statement and added to Drop Down List 2 via a cx-set-list-items statement. The list item added to list 2 will also automatically be selected via a cx-set-list-selections statement.

The extra button is necessary in this example because setting up the functionality of the OK button will cause it to close the dialog box each time it is clicked. To review how the Button in this example works, see Buttons (cx-create-button). This dialog box does not do anything when the OK button is clicked because we have substituted Boolean values for the apply-cb and update-cb arguments, which would normally be function calls like the button-cb argument is in the cx-create-button line. For more information on the apply-cb and update-cb functions, see cx-create-panel.

(define apply-cb #t)
(define update-cb #f)

(define table)
(define myDropList1)
(define myDropList2)

(define (button-cb . args)
  (cx-set-list-items myDropList2 (cx-show-list-selections myDropList1))
)

(define my-dialog-box (cx-create-panel "My Dialog Box" apply-cb update-cb))

(set! table (cx-create-table my-dialog-box "This is an example Dialog Box"))

(set! myDropList1 (cx-create-drop-down-list table "Drop Down List 1" 'row 0))
(cx-set-list-items myDropList1 (list "Item 1" "Item 2" "Item 3" "Item 4" "Item 5"))

(set! myDropList2 (cx-create-drop-down-list table "Drop Down List 2" 'row 1))

(cx-create-button table "Button" 'activate-callback button-cb 'row 2)

(cx-show-panel my-dialog-box)

Release 18.2 - © ANSYS, Inc. All rights reserved.