Auto-Filter Listbox

Create listbox uicontrol where strings can be filtered with a regular expression.
81 téléchargements
Mise à jour 25 juil. 2021

Afficher la licence

Usage:
H = listbox_autofilter()
H = listbox_autofilter('PropertyName', Value, ...)
H = listbox_autofilter(PARENT)
H = listbox_autofilter(PARENT, 'PropertyName', Value, ...)
Inputs:
Any combination of arguments that is valid for the construction of a
listbox uicontrol object. See 'uicontrol' and 'Uicontrol Properties'
documentation for more details.
Outputs:
H <1x1 uicontrol handle>
- Handle to listbox uicontrol object
Description:
listbox_autofilter effectively serves as a wrapper for a standard
listbox uicontrol object. See the 'uicontrol' documentation for more
information on constructing, setting/getting properties, and
interacting with a listbox uicontrol object.
Note, the 'Style' property will automatically be set to 'listbox' and
will override any other 'Style' property that may have been specified.
The 'Style' property should not be modified. Also, location and size
properties should not be modified because they are being automatically
handled through the use of the GUI Layout Toolbox.
The additional functionality provided by listbox_autofilter is the
pairing of the listbox uicontrol with an editable textbox that will
filter the listbox strings that are displayed through (case insensitive)
regular expression search.
Listbox selections will always provide an index relative to the full
set of strings, regardless of whether or not only a filtered subset of
the strings is being displayed. This is done to make it easier to use
the listbox selection to index into other variables that correspond to
the items in the listbox. See examples below for more details.
All listbox uicontrol callbacks are fully supported. The only potential
issue (for HG2) is that all callback event data will be 'struct' class.
So, the callbacks that are set shouldn't depend on receiving a specific
class of event data.
Examples:
f = figure;
str1 = {'This','is','example','text','to','display','in','listbox'};
h = listbox_autofilter(f, 'String', str1);
% If 'x' is typed into the textbox, then the only strings that will be
% displayed are {'example','text','listbox'}. Retrieving the index through
get(h, 'Value')
% will either return 3, 4, or 8 depending on the selection made, because
% those are the "absolute" indices of those strings in the full set of strings.
% Most listbox uicontrol properties can be modified as normal.
str2 = {'Attention','this','is','a','test','TESTING 1','TESTING 2','TESTING 3'};
set(h, 'String', str2);
% No matter how the listbox strings are filtered, the same 'str1' string
% will be displayed when its corresponding 'str2' string is selected.
set(h, 'Callback', @(src,evnt) disp(str1{get(src,'Value')}));
% Cleanup is automatically handled when listbox uicontrol object is deleted.
delete(h);
Requires:
GUI Layout Toolbox
HG1 version (R2014a and earlier): https://www.mathworks.com/matlabcentral/fileexchange/27758-gui-layout-toolbox
HG2 version (R2014b and later): https://www.mathworks.com/matlabcentral/fileexchange/47982-gui-layout-toolbox
References:
http://undocumentedmatlab.com/articles/auto-completion-widget

Citation pour cette source

Todd Baxter (2024). Auto-Filter Listbox (https://www.mathworks.com/matlabcentral/fileexchange/74790-auto-filter-listbox), MATLAB Central File Exchange. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2017a
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Publié le Notes de version
1.1.0.1

Uploaded new file

1.1.0

Layout is correctly displayed when placed in a larger layout

1.0.1.1

Update description to match function name change

1.0.1

Updated formatting and function naming convention

1.0.0.1

Uploaded an appropriately named .zip file containing the code.

1.0.0