Author Topic: List Box Multiple Selection Improvisation  (Read 4576 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 493
List Box Multiple Selection Improvisation
« on: March 27, 2015, 01:38:52 PM »
Hello

I want to make two list boxes - side by side. as per below image :

http://www.jefferypsanders.com/DCL_PART301.jpg

Initially First List Box shall consist of multiple Items and Second List Box shall be empty.

As soon as user double clicks on any Item in First List Box, it should get deleted from First List Box and Get Added in Second List Box.

Reverse should also be true i.e. as soon as user double clicks on any item in Second List Box, it should get deleted from there and get added in First List Box.

In the end when user presses OK, I want to get all items in Second List Box.

How to achieve it ?
« Last Edit: March 27, 2015, 01:54:02 PM by mailmaverick »

ChrisCarlson

  • Guest
Re: List Box Multiple Selection Improvisation
« Reply #1 on: March 27, 2015, 02:20:48 PM »
Suggest you refer to here

http://www.afralisp.net/dialog-control-language/

Nothing too crazy about your request

mailmaverick

  • Bull Frog
  • Posts: 493
Re: List Box Multiple Selection Improvisation
« Reply #2 on: March 28, 2015, 05:19:12 AM »
Suggest you refer to here

http://www.afralisp.net/dialog-control-language/

Nothing too crazy about your request

I agree to the link you have given. But for that I will first have to do lot of learning of DCL, for which currently I do not have time.

If anyone has already done it, please provide the code for the same.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: List Box Multiple Selection Improvisation
« Reply #3 on: March 28, 2015, 05:56:33 AM »
Here is the DCL codes to push you a little forward to your goal  :wink:

Code: [Select]
test : dialog { label = "Sample Dialog:"; width = 70;
     : boxed_row   {
     : list_box { label = "Choose Item"; key = "a"; height = 16;}
     : list_box { label = "Choose Item"; key = "b"; }
                   }
     : boxed_row {
     : button { label = "Okay";   key = "oki"; is_default = true; }
     : button { label = "Cancel"; key = "esc"; is_cancel = true;  }
                 }
 }


snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: List Box Multiple Selection Improvisation
« Reply #4 on: March 28, 2015, 07:52:45 AM »
Using Std DCL, not sure the double click method is possible, you could single click by utilizing the "allow_accept = true" method, or better yet allow multiple selections then between the list boxes have two arrows one less than which deducts items from the second list box, and a greater than arrow to add items from 1st box to second box.


Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: List Box Multiple Selection Improvisation
« Reply #5 on: March 28, 2015, 08:44:53 AM »
Here's a quick example for you to consider:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:example ( / *error* dch dcl des idx ls1 ls2 )
  2.  
  3.     (defun *error* ( msg )
  4.         (if (and (= 'int (type dch)) (< 0 dch))
  5.             (unload_dialog dch)
  6.         )
  7.         (if (= 'file (type des))
  8.             (close des)
  9.         )
  10.         (if (and (= 'str (type dcl)) (setq dcl (findfile dcl)))
  11.             (vl-file-delete dcl)
  12.         )
  13.         (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
  14.             (princ (strcat "\nError: " msg))
  15.         )
  16.         (princ)
  17.     )
  18.  
  19.     (repeat (setq idx 15)
  20.         (setq ls1 (cons (strcat "Item " (itoa idx)) ls1)
  21.               idx (1- idx)
  22.         )
  23.     )
  24.  
  25.     (if
  26.         (and
  27.             (setq dcl (vl-filename-mktemp "tmp.dcl"))
  28.             (setq des (open dcl "w"))
  29.             (foreach str
  30.                '(
  31.                     "listbox : list_box"
  32.                     "{"
  33.                     "    width = 30;"
  34.                     "    height = 20;"
  35.                     "    fixed_width = true;"
  36.                     "    fixed_height = true;"
  37.                     "}"
  38.                     "example : dialog"
  39.                     "{"
  40.                     "    label = \"List Box Example\";"
  41.                     "    spacer;"
  42.                     "    : row"
  43.                     "    {"
  44.                     "        : listbox { key = \"ls1\"; }"
  45.                     "        : listbox { key = \"ls2\"; }"
  46.                     "    }"
  47.                     "    ok_only;"
  48.                     "}"
  49.                 )
  50.                 (write-line str des)
  51.             )
  52.             (not (setq des (close des)))
  53.             (< 0 (setq dch (load_dialog dcl)))
  54.             (new_dialog "example" dch)
  55.         )
  56.         (progn
  57.             (fill_list "ls1" ls1)
  58.            
  59.             (action_tile "ls1"
  60.                 (vl-prin1-to-string
  61.                    '(if (= 4 $reason)
  62.                         (setq ls2 (fill_list "ls2" (append ls2 (list (nth (atoi $value) ls1))))
  63.                               ls1 (fill_list "ls1" (LM:removenth (atoi $value) ls1))
  64.                         )
  65.                     )
  66.                 )
  67.             )
  68.             (action_tile "ls2"
  69.                 (vl-prin1-to-string
  70.                    '(if (= 4 $reason)
  71.                         (setq ls1 (fill_list "ls1" (append ls1 (list (nth (atoi $value) ls2))))
  72.                               ls2 (fill_list "ls2" (LM:removenth (atoi $value) ls2))
  73.                         )
  74.                     )
  75.                 )
  76.             )
  77.             (if (and (= 1 (start_dialog)) ls2)
  78.                 (progn
  79.                     (princ "\nThe user selected the following items:")
  80.                     (foreach x ls2 (terpri) (princ x))
  81.                 )
  82.                 (princ "\n*Cancel*")
  83.             )
  84.         )
  85.     )
  86.     (*error* nil)
  87.     (princ)
  88. )
  89.  
  90. (defun fill_list ( key lst )
  91.     (start_list key)
  92.     (foreach itm lst (add_list itm))
  93.     (end_list)
  94.     lst
  95. )
  96.  
  97. ;; Remove Nth  -  Lee Mac
  98. ;; Removes the item at the nth index in a supplied list
  99.  
  100. (defun LM:removenth ( n l )
  101.     (if (and l (< 0 n))
  102.         (cons (car l) (LM:removenth (1- n) (cdr l)))
  103.         (cdr l)
  104.     )
  105. )
  106.  

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: List Box Multiple Selection Improvisation
« Reply #6 on: March 28, 2015, 12:28:44 PM »
Nice Lee, I was unaware the double click could be implemented in selecting items from a list box like you did above.

I was unaware of the $reason codes....until now.
« Last Edit: March 28, 2015, 12:44:25 PM by snownut2 »

mailmaverick

  • Bull Frog
  • Posts: 493
Re: List Box Multiple Selection Improvisation
« Reply #7 on: March 28, 2015, 01:51:24 PM »
WOW !!! Lee Mac to the rescue once again.

Lee !!! You are a God or what !!!

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: List Box Multiple Selection Improvisation
« Reply #8 on: March 28, 2015, 02:54:57 PM »
Thanks guys - I'm glad it helps  :-)

If you have any questions about the code, feel free to ask.

Lee