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
Mario Malic
2020년 11월 2일
편집: Mario Malic
2020년 11월 2일
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
2020년 11월 2일
You can use regexp or contains to match parts of strings.
J. Alex Lee
2020년 11월 3일
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
2020년 11월 5일
답변 (1개)
J. Alex Lee
2020년 11월 3일
2 개 추천
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
Christelle Rodier
2020년 11월 5일
J. Alex Lee
2020년 11월 5일
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
2020년 11월 5일
"Do you have a further idea how to deal with that?"
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!