dcl_ListBox_SelectString not working?

Started by funkitect, September 11, 2013, 11:57:24 AM

Previous topic - Next topic

funkitect

I can't get dcl_ListBox_SelectString to work using version 7.0.0.14.  I've got the control in multi-select mode and I can confirm that I have the correct text being feed into the function using "(alert scale1)" as shown in my code below.  Nothing is ever selected.



      (cond
         (#lsLastScales
            ;select all the scales in the list...'("48" "24" "96")
            ;I'm not at all sure if this is a valid way to select multiple
            ;items in a listbox since I can't get the function to work!
            (foreach scale1 #lsLastScales
                (alert scale1)
                (dcl_ListBox_SelectString LSscale scale1)
            )
         )
            
         ((> (atoi SFdflt) 0)
            ;select just the default scale..i.e. "48"
            ;This doesn't work either....
            (alert scale1)
            (dcl_ListBox_SelectString LSscale SFdflt)
         )
         (t
            ;just select the first item on the list
            (dcl_ListBox_SelectItem LSscale 0 t)
         )
      )

....bug or user error? 

James

owenwengerd

The SelectString function uses the LB_SELECTSTRING message, and according to MSDN that message will not work in a multi-select listbox. You can use FindString + SelectItem instead. I'll have a look at the function to see if it's feasible to fake it for a multi-select listbox, and if not, add a note to the documentation.

funkitect

Hi Owen,

I came to the same conclusion for the workaround and it works perfectly for multiple selections. There is still a bit of a problem.  I've found that if one of the items in the listbox is an empty string "" and you search for "" all the items get selected.

      (cond
         (#lsLastScales
            ;select all the scale in the list...'("" "48" "24" "96")
            (foreach scale1 #lsLastScales
                (dcl_ListBox_SelectItem LSscale (dcl_ListBox_FindString LSscale scale1) t)
            )
         )
         
         ((> (atoi SFdflt) 0)
            ;select just the default scale..i.e. "48"
            (dcl_ListBox_SelectItem LSscale (dcl_ListBox_FindString LSscale SFdflt) t)
         )
         (t
            ;just select the first item on the list
            (dcl_ListBox_SelectItem LSscale 0 t)
         )
      )

owenwengerd

You need to check the result of FindString to make sure something was found before you call SelectItem, as SelectItem(-1) selects all items in the list.

funkitect

OK...that fixes selecting everything...but now it selects nothing.

If the list box contains an empty string FindString will not find it (returns -1) when searching for "".

      (foreach scale1 #lsLastScales
          (setq index (dcl_ListBox_FindString LSscale scale1))
          (if (> index -1)
              (dcl_ListBox_SelectItem LSscale index t)
          )
      )

owenwengerd

FindString searches for any item that starts with the search text, so it doesn't really make sense to search for an empty string. It sounds like FindStringExact would be more appropriate.

funkitect

Jeee-sus!  Didn't notice that one!   Unfortunately, FindStringExact doesn't find a blank string either.  I'll write my own search program as a work around.

James LeVieux

funkitect

In case anyone runs into this also...this seems to work:

(defun ccFindStringExact (listBoxControl searchStr / i s rtrn)
   (setq i 0 n (dcl_ListBox_GetCount ListBoxControl))
   (while (< i n)
      (setq str (dcl_ListBox_GetItemText ListBoxControl i))
      (if (= str SearchStr)
         (setq
            rtrn i
            i n
         )
      )
      (setq i (+ i 1))
   )
   (if rtrn rtrn -1)
)