How do i add search functionality into my drop down menu in my GUI?
5 ビュー (過去 30 日間)
古いコメントを表示
I have a GUI that loads data and plots it. I have drop down menus for selecting the parameters to plot. I wanted to add search functionality to the drop down menu. Any suggestions?
2 件のコメント
Rishabh Rathore
2018 年 5 月 31 日
Can you elaborate as to search what? Search from existing values for drop down?
回答 (2 件)
Arsalan jamialahmadi
2019 年 2 月 13 日
You can add en uieditfield called MyEditField to your app and for that apply a "ValueChanging" callback to be able to search your MyDropDown:
changingValue = event.Value;
List=[];
if ~isempty(app.MyEditField)
for i=1:length(app.OriginalList)
if contains(app.OriginalList{i},changingValue)
List=[List,app.OriginalList(i)];
end
end
end
if isempty(app.MyEditField)
List=app.OriginalList;
end
if ~isempty(List)
app.MyDropDown.Items=List;
end
if isempty(event.Value)
app.MyDropDown.Items=app.OriginalList;
end
if ~isempty(event.Value) && isempty(List)
app.MyDropDown.Items={};
end
0 件のコメント
Bereketab Gulai
2020 年 5 月 25 日
Here is much Modified of Arsalan jamialahmadi
% Value changing function: TestTypeSearchEditField
function TestTypeSearchEditFieldValueChanging(app, event)
persistent originalTestTypeList; % save the original list
if isempty(originalTestTypeList)
originalTestTypeList = app.TestTypeDropDown.Items;
pause(0.5); % sync value (in case...)
end
changingValue = event.Value;
Utility.filterDropdownList(app.TestTypeDropDown, originalTestTypeList, changingValue);
end
In Utility Class (You can create this)
function filterDropdownList(uidropdownControl, originalList, changingValue)
List=[];
if ~isempty(changingValue)
for c = 1:length(originalList)
if contains(originalList{c},changingValue, "IgnoreCase",true)
List = [List,originalList(c)];
end
end
end
if ~isempty(List) % Something is found
uidropdownControl.Items = List;
elseif ~isempty(changingValue) && isempty(List) % Nothing is found
uidropdownControl.Items = {};
else % Restore otherwise
uidropdownControl.Items = originalList;
if isempty(uidropdownControl.ItemsData)
uidropdownControl.Value = originalList{1};
else
if isnumeric(uidropdownControl.ItemsData)
uidropdownControl.Value = uidropdownControl.ItemsData(1);
else
uidropdownControl.Value = uidropdownControl.ItemsData{1};
end
end
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!