List Box with Filter
|Function Syntax||(LM:filtlistbox <msg> <lst> <mtp>)|
|View HTML Version||FilteredListBoxV1-1.html|
|msg||String||List box dialog title|
|lst||List||List of strings to display in the list box|
|mtp||Boolean||Flag to control whether the user may select multiple items (T = Allow Multiple)|
|List||List of selected item(s) or nil if user pressed Cancel|
Similar to my existing List Box function, this function also presents the user with a dialog interface containing a list box tile from which the user may select one or more items (depending on the function parameters), however, the displayed dialog for this function also includes an edit box tile, enabling the user to filter the list of items displayed.
By default, the filter string is set to the asterisk wildcard operator (*), hence displaying all items in the supplied list of strings. The user may filter the set of items displayed in the list box by entering a new filter string and pressing Enter to submit the filter to the function.
The filter string is case-insensitive and may use wildcard patterns to match a set of items as demonstrated by the following example:
Here, upon invoking the function, the initial list box (shown on the left) displays all items with a filter string of "*"; upon entering a wildcard filter string of "*#", the list of items (shown on the right) is filtered to include only those which match the entered pattern (i.e. those items ending with a numerical character).
The filter may be removed by clearing the filter edit box and pressing Enter, or by using a filter string of "*" to match all items.
Following a selection of item(s) from the list box, if the user subsequently presses OK to submit the selection, the function will return a list of the selected item(s) from the supplied data list; else nil will be returned if either the dialog could not be loaded or the user pressed Cancel before submitting a selection.
(defun c:test ( / def lst ) (while (setq def (tblnext "layer" (not def))) (setq lst (cons (cdr (assoc 2 def)) lst)) ) (LM:filtlistbox "Select a Layer" (acad_strlsort lst) t) )