Search function in drop down menu in AppDesigner?
Mostrar comentarios más antiguos
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 comentarios
Mario Malic
el 2 de Nov. de 2020
Editada: Mario Malic
el 2 de Nov. de 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
el 2 de Nov. de 2020
You can use regexp or contains to match parts of strings.
J. Alex Lee
el 3 de Nov. de 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
el 5 de Nov. de 2020
Respuestas (1)
J. Alex Lee
el 3 de Nov. de 2020
2 votos
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 comentarios
Christelle Rodier
el 5 de Nov. de 2020
J. Alex Lee
el 5 de Nov. de 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
el 5 de Nov. de 2020
"Do you have a further idea how to deal with that?"
Categorías
Más información sobre App Building en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!