How do i add search functionality into my drop down menu in my GUI?

10 visualizaciones (últimos 30 días)
Anuj
Anuj el 30 de Mayo de 2018
Respondida: Bereketab Gulai el 25 de Mayo de 2020
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 comentarios
Rishabh Rathore
Rishabh Rathore el 31 de Mayo de 2018
Can you elaborate as to search what? Search from existing values for drop down?
Anuj
Anuj el 11 de Jul. de 2018
Yes. Search for already loaded data.

Iniciar sesión para comentar.

Respuestas (2)

Arsalan jamialahmadi
Arsalan jamialahmadi el 13 de Feb. de 2019
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

Bereketab Gulai
Bereketab Gulai el 25 de Mayo de 2020
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

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by