Code Red > Visual DCL Programming

Add/Remove item from a Listbox

(1/1)

Matthew H:
I have two Listbox's.
http://help.autodesk.com/view/ACD/2020/ENU/?guid=GUID-C01592FC-3A6B-48A2-952C-15307F0DAC5F
Listbox1 never changes and has (Item A, Item B, Item C, Item D, Item E, ect)
The Listbox2 is empty.

Is there a way to select(single and multiple) items from Listbox1 to add to Listbox2?
As well as remove(single and multiple) items from Listbox2.
The finished list of Listbox2 would like similar to (Item B, Item B, Item B, Item E, Item C)

I notice Lee Mac has the Listbox function to reorder items in a Listbox, which is useful
http://www.lee-mac.com/listboxfunctions.html

I have attached an example below.

Thank you for your time,
Matthew H.

Lee Mac:
Here's a quick example for you to consider:


--- Code - Auto/Visual Lisp: ---(defun c:test ( / *error* asc dch dcl des lst sel )     (defun *error* ( msg )        (if (= 'int  (type dch)) (unload_dialog dch))        (if (= 'file (type des)) (close des))        (if (and (= 'str  (type dcl)) (findfile dcl)) (vl-file-delete dcl))        (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))            (princ (strcat "\nError: " msg))        )        (princ)    )     (if        (and            (setq dcl (vl-filename-mktemp nil nil ".dcl"))            (setq des (open dcl "w"))            (foreach str               '(                    "lb : list_box"                    "{"                    "    multiple_select = true;"                    "    fixed_width = true;"                    "    fixed_height = true;"                    "    width = 30;"                    "    height = 15;"                    "}"                    "bt : button"                    "{"                    "    fixed_width = true;"                    "    fixed_height = true;"                    "    width = 10;"                    "    height = 2;"                    "}"                    "test : dialog"                    "{"                    "    spacer_1;"                    "    : row"                    "    {"                    "        : lb { key = \"lb1\"; }"                    "        : column"                    "        {"                    "            fixed_height = true;"                    "            : bt { label = \"--->\"; key = \"add\"; }"                    "            : bt { label = \"<---\"; key = \"rem\"; }"                    "        }"                    "        : lb { key = \"lb2\"; }"                    "    }"                    "    spacer;"                    "    ok_only;"                    "    spacer;"                    "}"                )                (write-line str des)            )            (not (setq des (close des)))            (< 0 (setq dch (load_dialog dcl)))            (new_dialog "test" dch)        )        (progn            (setq asc 65)            (repeat 10 (setq lst (cons (strcat "Item " (chr asc)) lst) asc (1+ asc)))            (setq lst (reverse lst))                        (dclist "lb1" lst)             (action_tile "add"                (vl-prin1-to-string                   '(mapcar 'dclist '("lb1" "lb2")                        (mapcar 'set '(lst sel)                            (shiftitems (read (strcat "(" (get_tile "lb1") ")")) lst sel)                        )                    )                )            )             (action_tile "rem"                (vl-prin1-to-string                   '(mapcar 'dclist '("lb2" "lb1")                        (mapcar 'set '(sel lst)                            (shiftitems  (read (strcat "(" (get_tile "lb2") ")")) sel lst)                        )                    )                )            )                        (start_dialog)        )    )    (*error* nil)    (princ)) (defun dclist ( key lst )    (start_list key)    (foreach itm lst (add_list itm))    (end_list)) (defun shiftitems ( idx lb1 lb2 / int )    (setq int -1          lb2 (reverse lb2)          lb1 (vl-remove-if '(lambda ( x ) (if (member (setq int (1+ int)) idx) (setq lb2 (cons x lb2)))) lb1)    )    (list lb1 (reverse lb2))) (princ)

Navigation

[0] Message Index

Go to full version