How to fill ComboBox List from ADOLisp query result List

Started by jrupert, January 22, 2014, 09:10:19 AM

Previous topic - Next topic

jrupert

I have a List from a query of SQL database.  I need to fill a ComboBox List from this query list.
I have tried...
(setq L1 (cdr Result))
(dcl_ComboBox_Clear GBSCC_FormGBSCC_CBoxType)
(dcl_Control_SetList GBSCC_FormGBSCC_CBoxType L1)

but I get an error:
Invalid argument type
Function: dcl_Control_SetList
Argument: 2

Can anyone inform me how to accomplish this task.

Fred Tomke

Hello, the list must be a list of strings.

Code (autolisp) Select

(setq lstResult (list "Line1" "Line2" "Line3"))
(dcl_Control_SetList GBSCC_FormGBSCC_CBoxType lstResult)

;; in the past I did
(dcl_ComboBox_Clear GBSCC_FormGBSCC_CBoxType)
(dcl_Control_AddList GBSCC_FormGBSCC_CBoxType lstResult)



Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

jrupert

Fred...Thank you for your response!
I guess I did not fully qualify my question, but your answer is correct.

As the result list from a ADOLisp query contains at least (1) sub-list, representing the data values, the real question that I had was how to parse the result query list.

The result query list has a structure of (("") ("value") ("value") ("value")...etc).

If I understand correctly, the combobox list structure needs to be ("value" "value" ...etc).

What I was questioning was how to parse the result list into a list that would be accepted by the combobox.  I finally came up with the following.

(if (setq Result (ADOLisp_DoSQL ConnectionObject SQLStatement))
                (progn
                    ;CAPTURE SUB-LIST OF LIST
                    (setq L1 (cdr Result))

                    ;CONVERT QUERY LIST L1 TO CBoxMaterial ITEMS LIST
                    ;...GET NUMBER OF ELEMENTS IN QUERY LIST
                    (setq numItems (length L1))

                    ;CREATE COUNTER
                    (setq cntr 1)

                    ;CREATE LIST-OF-STRINGS FROM 1ST VALUE OF QUERY LIST
                    (setq L (list (car (car L1))))

                    ;APPEND VALUES FROM QUERY LIST TO LIST-OF-STRINGS "L"
                    (while (< cntr numItems)
                        (setq L (append L (list (car (nth cntr L1)))))
                        (setq cntr (+ cntr 1))
                    )
                   
                    (dcl_ComboBox_Clear GBSCC_FormGBSCC_CBoxMaterial)
                    (dcl_Control_SetList GBSCC_FormGBSCC_CBoxMaterial L)
                )

                (alert "Query Failed")
            )

I have posted this in an attempt to allow others not to go thru the frustration that I did in finally figuring this out.  This took days searching on the NET to finally piece it together.  Relevant help documentation for AutoLisp, OpenDCL, etc. is difficult at best to find.

Again, Thank you for your response!

owenwengerd

#3
For general lisp questions you'll get more help at The Swamp or the Autodesk discussion groups.

In this case you should use the (mapcar) function:
Code (autolisp) Select
(setq L (mapcar 'car L1))
Owen Wengerd (Outside The Box) / ManuSoft

Fred Tomke

Hi, Owen is right. Do never, never, never a (setq mylist (append mylist (list newitem)) in your code.
Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

khann

Hi, Fred.  8)
I often used this, you said that 3 never codes.
Would you tell me why never ?
Is there any critical reason ?
Thanks.

Fred Tomke

Hi, khann, it's not OpenDCL related but test both of the commands. You should feel a recognizable difference.
Code (autolisp) Select
(defun c:test1(/ intCnt lstVal )
  (setq intCnt 0
lstVal '())
  (repeat 20000
    (setq lstVal (append lstVal (list (setq intCnt (1+ intCnt)))))
  ); repeat
  (princ)
); test1


(defun c:test2(/ intCnt lstVal)
  (setq intCnt 0
lstVal '())
  (repeat 20000
    (setq lstVal (cons (setq intCnt (1+ intCnt)) lstVal))
  ); repeat
  (setq lstVal (reverse lstVal))
  (princ)
); test2

Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

khann

Thanks Fred! for your sample codes.
I tested the two.

"Test1" takes about 14 seconds.
But "Test2" just 5s.

Now I could see what you mean.
Thanks !!!  ::)



Fred Tomke

5 seconds for test2 seems to be too much. It should take less than a second (so it was on my notebook).
Back to your initial question: for the case you need an ID as integer value and a string as a display value, you can fill the combo line with the text and assign the integer values as internal data.

Code (autolisp) Select
(setq lstValues (sqlite_query strSQLiteFile "SELECT ID,NAME FROM STRM_STREETS_TBD"))
(dcl_Control_SetList cbbDomain (mapcar '(lambda (x) (cdr (assoc "NAME" x))) lstValues)
(dcl_Control_SetItemData cbbDomain (mapcar '(lambda (x) (cdr (assoc "ID" x))) lstValues)

(defun c:cbbDomain_OnSelChanged (intIndex strName)
  (setq intSelectedStreet (dcl_ComboBox_GetItemData cbbDomain intIndex))
); c:cbbDomain_OnSelChanged


Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]