3.6.3. List Example

This example shows how the cx-create-list, cx-set-list-items, cx-set-list-selections, and cx-show-list-selections macros work. Both of the lists are created via cx-create-list statements. The first list only allows for three visible list items at a time while the second list allows for five to be shown at a time. This is an example of how to set the size of your list via the visible-lines argument.

Upon opening the dialog box the first list will automatically load all five list items via a cx-set-list-items line while the second list starts empty. By selecting one or multiple list items from the first list and then clicking on Button, the selected list items from list 1 will be gathered via a cx-show-list-selections statement and added to list 2 via a cx-set-list-items statement. The list items 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 myList1)
(define myList2)

(define (button-cb . args)
  (cx-set-list-items myList2 (cx-show-list-selections myList1))
  (cx-set-list-selections myList2 (cx-show-list-selections myList1))
)

(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! myList1 (cx-create-list table "List 1" 'visible-lines 3 'multiple-selections #t 'row 0))
(cx-set-list-items myList1 (list "Item 1" "Item 2" "Item 3" "Item 4" "Item 5"))

(set! myList2 (cx-create-list table "List 2" 'visible-lines 5 'multiple-selections #t '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.