Search function in drop down menu in AppDesigner?
Mostra commenti meno recenti
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
Mario Malic
il 2 Nov 2020
Modificato: Mario Malic
il 2 Nov 2020
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.
Adam Danz
il 2 Nov 2020
You can use regexp or contains to match parts of strings.
J. Alex Lee
il 3 Nov 2020
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.
Christelle Rodier
il 5 Nov 2020
Risposte (1)
J. Alex Lee
il 3 Nov 2020
2 voti
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
Christelle Rodier
il 5 Nov 2020
J. Alex Lee
il 5 Nov 2020
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.
Adam Danz
il 5 Nov 2020
"Do you have a further idea how to deal with that?"
Categorie
Scopri di più su App Building in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!