Author Topic: help: select mulitple items from listbox  (Read 915 times)

andrew

  • Full Member
  • ***
  • Posts: 185
help: select mulitple items from listbox
« on: January 15, 2013, 02:12:03 PM »
hello all. happy new year.

im a bit rusty, so i need a bit of help if you can provide it.

in my project i have a listbox, that displays contents of a text file.
i click a button and it takes the selected lines (one at a time) and adds them to a list view, separating certain lines into certain columns. i would like to make it where i can select all in the list box or select multiple lines to add to the list view.

i have the properties for the listbox set to muliple for selection style. how can i get these items into the list view as ALL or MULTIPLE lines.

here is code snippet im currently using that i have working for 1 line at a time

i appreciate any and all help

Code: [Select]
(setq items (dcl_ListBox_GetSelectedItems dwgbrowser_Form3_ListBox1))

;;get title
(setq title (substr (nth 0 items) 1 42)) ;41

;;gets rev
(setq rev (substr (nth 0 items) 54)) ;53
    (while (< (strlen rev) 6)
      (setq rev (strcat rev " "))
    ); end while

;;gets dwg number
(setq dwgnum (substr (nth 0 items) 43 11)) ;11
(SETQ amrev1 dwgnum)

(defun make_list (strItem)
 (list strItem)
)

(if sho_lst
 (progn
  (setq make_lst (mapcar 'list (make_list title) (make_list dwgnum) (make_list rev)))
  (setq sho_lst (append sho_lst make_lst))
 )
(progn
  (setq make_lst (mapcar 'list (make_list title) (make_list dwgnum) (make_list rev)))
  (setq sho_lst (append sho_lst make_lst))
 )
)

(dcl_ListView_FillList dwgbrowser_Form3_ListView1 sho_lst)

roy_043

  • Full Member
  • ***
  • Posts: 182
Re: help: select mulitple items from listbox
« Reply #1 on: January 17, 2013, 08:56:36 AM »
Maybe this helps:

  1. ; (setq items (dcl_ListBox_GetSelectedItems dwgbrowser_Form3_ListBox1)) ; List of Strings
  2. (setq items
  3.   '(
  4.     "DwgTitle1                                 DwgNum1    A"
  5.     "DwgTitle2                                 DwgNum2    B"
  6.   )
  7. )
  8.  
  9. (defun Item->RowList (item)
  10.   (list
  11.     (vl-string-trim " " (substr item 1 42))  ; Title.
  12.     (vl-string-trim " " (substr item 43 11)) ; Dwg number
  13.     (vl-string-trim " " (substr item 54))    ; Revision
  14.   )
  15. )
  16.  
  17. (defun c:ListViewTest ()
  18.   (setvar 'cmdecho 0)
  19.   (command "_OPENDCL")
  20.   (setvar 'cmdecho 1)
  21.   (dcl_Project_Load "ListViewTest.odcl" T)
  22.   (dcl_Form_Show ListViewTest_Form1)
  23.   (princ)
  24. )
  25.  
  26. (defun c:ListViewTest_Form1_OnInitialize (/)
  27.   (dcl_ListView_AddColumns
  28.     ListViewTest_Form1_ListView1
  29.     (list
  30.       (list "Title"      0 (dcl_ListView_CalcColWidth ListViewTest_Form1_ListView1 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"))
  31.       (list "Dwg number" 0 (dcl_ListView_CalcColWidth ListViewTest_Form1_ListView1 "AAAAAAAAAAAAA"))
  32.       (list "Revision"   0 (dcl_ListView_CalcColWidth ListViewTest_Form1_ListView1 "AAAAAAAA"))
  33.     )
  34.   )
  35. )
  36.  
  37. (defun c:ListViewTest_Form1_ButtonAppend_OnClicked (/)
  38.   (dcl_ListView_Clear ListViewTest_Form1_ListView1)
  39.   (dcl_ListView_FillList
  40.     ListViewTest_Form1_ListView1
  41.     (setq *sho_lst*
  42.       (append *sho_lst* (mapcar 'Item->RowList items))
  43.     )
  44.   )
  45. )
  46.  
  47. (defun c:ListViewTest_Form1_ButtonReplace_OnClicked (/)
  48.   (dcl_ListView_Clear ListViewTest_Form1_ListView1)
  49.   (dcl_ListView_FillList
  50.     ListViewTest_Form1_ListView1
  51.     (setq *sho_lst* (mapcar 'Item->RowList items))
  52.   )
  53. )
  54.  
  55. (princ "\nc:ListViewTest")
  56. (princ)
  57.  

andrew

  • Full Member
  • ***
  • Posts: 185
Re: help: select mulitple items from listbox
« Reply #2 on: January 17, 2013, 02:35:55 PM »
works perfect

thanks