04-27-2009 11:48 AM - edited 04-27-2009 11:48 AM
Have you ever wanted to implement an auto-complete string in your LabVIEW UI? I did this for Quick Drop in LabVIEW 8.6, and it's really easy:
That string control in the Quick Drop UI isn't really a string, it's a combo box control with the side arrow hidden via the Control Editor. When Quick Drop launches, I populate the Strings[] property of the Combo Box with all possible palette object names. As you type an object name, I'm simply taking advantage of the built-in auto complete that combo boxes already have. I had to write a little extra code to handle the case when the user presses the up or down arrow while typing in the combo box. Normally this will expand the combo box drop-down list. Since I don't want Quick Drop users to ever interact with the combo box drop-down list, I discard the arrow key press and instead, give focus to the listbox below the string.
04-27-2009 12:13 PM
Would be nice to have that code fragment for download, although it's not difficult to do on ones own.
Felix
04-27-2009 12:59 PM - edited 04-27-2009 12:59 PM
Could you give some pointers as to how to hide the drop down in the control editor? I have tried a couple of things but failled to get a nice solution - I always end up with a grey semi transparent square... see attached pic.
In addition to the method described in the pic I also tried filling the button with the transparent color and the mysterious square remained!
Thanks,
Shaun
04-27-2009 02:35 PM - edited 04-27-2009 02:36 PM
Is there any chance, as part of this thread, or as part of a future nugget, we can get the secret to how you pulled off the bottom part of the Quick Drop dialog? I'd like to know how to present a filtered list as someone types. There is a second control, right? It's not all a combo box?
By the way, thanks for presenting this nugget! I have been wondering how to do this for quite some time.
Oh, yeah, I concur with Felix's statement above.
04-27-2009 02:55 PM
To customize the combo box, you can color the area transparent, then move it to the back and resize it to (1,1) using the alignment menus and hide it behind the control. You can also find an example showing autocomplete in a string in the first post of the thread linked to in the next paragraph.
As for the search, I created my own version of QD a while back, which shows how to do this. You can find it here. The code isn't the cleanest, but the search part is well contained within a single VI.
04-27-2009 03:07 PM
Thanks tst! 🙂
It seems I was having a bit of a brain fail this morning - I forgot about that little guy!
Shaun
04-27-2009 03:58 PM
I have attached a VI to this post (saved in 8.6) that contains a copy of the combo box from Quick Drop. It has the side arrow hidden, which, as tst explained, can be accomplished by resizing it to 1 pixel, and hiding it behind the control. You'll also notice that my combo box is surrounded by a black border decoration. I did this to give it as much of a dialog appearance as I could, since I had to start with a simple combo box (from the Classic controls subpalette) to be able to customize it the way I wanted in the control editor.
To answer InternationAL's question, the area under the Quick Drop text box is a listbox. As you type in the text box, I am doing a search of all the palette object names for anything that matches what is typed (this is triggered by the key down and timeout cases of an Event Structure). Once the match search is complete, I repopulate the listbox with the names of anything that matched.
04-28-2009 08:58 AM
Don't you have to turn on the "Update value while typing" for the combo box, or else the filtering of the listbox won't occur with the value currently displayed? But, if you turn that on, the autocomplete turns off. How do you get both autocomplete and "Update value while typing" to be on at the same time? On my end, I seem to be able to get only one or the other.
Plus, what's the search function being used? I like how in Quick Drop, you can search for two different string chunks, like "rect" and "pola", if you type in "rect pola", and you'll find, for example, the "Rectangular to Polar" and "Polar to Rectangular" functions. I am currently using the "Match Pattern" LabVIEW primitive. Should I be using a different one, or is the Quick Drop search a little more complicated than can be implemented with a single LabVIEW function?
Thanks for a great weekly nugget!
04-28-2009 09:57 AM
InternationAL wrote:
...or is the Quick Drop search a little more complicated than can be implemented with a single LabVIEW function?
It's more complicated. See the link in my previous post for an example implementing something similar.
04-28-2009 10:05 AM