Search function in drop down menu in AppDesigner?

Hi everyone!
I am currently working on a tool where the user selects different signals from a dropdown menu an then the tool takes the signals and processes them.
The problem is that there is about 150 signals in that drop down menu and I am searching for an option not to scroll down all the signals until the desired is found. SOmething like a search function where I can type parts of that signal (eg. signal is ID_065_SIG03_Accel) and I want to type "accel" to reduca the drop down menu that signals containing that part.
Many thanks in advance for your help!

4 Commenti

Hello,
It's possible, I can imagine process going something similar to this:
You would create a Edit Field (text) component where you would search the contents of DropDown Menu.
DropDown menu has two properties of interest, Value and Items. Items is a cell array that contains the options, where Value takes one of these options.
You can create a callback that would search for the Edit Field component text in Items. You can try with function contains (maybe better with regexp as Adam suggested, as I haven't worked with any of these). You will need to have a property/cell variable that will contain whole dataset for Items, replace it with filtered one when you type in something. When the Edit Field component is empty, then you can revert back to the whole dataset.
function ValueChangedFcn(app,event)
if isempty(app.TextToFind.Value) % If empty
app.DropDownMenu.Items = app.CompleteDropDownItems; % whole dataset
else
idx = contains(app.DropDownMenu.Items, app.TextToFind.Value)
Filtered_Values = app.DropDownMenu.Items(idx);
app.DropDownMenu.Items = Filtered_Values; % Consider a case as well when property Value is not in Items
% you'd get a warning or even an error
end
This is just a rough idea how would I do it, code above is not tested.
You can use regexp or contains to match parts of strings.
Doesn't the dropdown already do some simple completion suggestions (when you set its Editable property to true)?
Another approach to avoid matching could be to calculate the distances (levenshtein, e.g.) between the typed word and filter on that distance in case you make a typo.
Many thanks for your help!
The solution you provided is a pretty nice second option in case the other solution cannot handle parts of the strings.

Accedi per commentare.

Risposte (1)

J. Alex Lee
J. Alex Lee il 3 Nov 2020
Just confirmed, if you set the "Editable" property of a uidropdown to "on", you get some simple filtering of the Items based on what you type into the dropdown.

3 Commenti

Hello,
thank you, that's actually quite useful. But in this case you have to know the signal_name from the beginning.
BUt I still have a problem: In other programs, you can type something like *accel, when the orginal name is ID_041_front_accel.
Do you have a further idea how to deal with that?
Hmm, not if the existing functionality doesn't already do it. I don't think the intrinsic filtering functionality of the uidropdown is exposed to be able to tweak, but i could be wrong.

Accedi per commentare.

Categorie

Scopri di più su App Building in Centro assistenza e File Exchange

Commentato:

il 5 Nov 2020

Community Treasure Hunt

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

Start Hunting!

Translated by