필터 지우기
필터 지우기

Is it possible to allow a re-selection of the same option from a drop down menu?

조회 수: 4 (최근 30일)
Desmond Harris
Desmond Harris 2023년 5월 12일
답변: Saffan 2023년 6월 27일
I have a drop down menu that opens an additional app if its option is chosen. Once I return the the main app, I would like to choose the same option again from the drop down in order to view the entries I placed in the sub app. Is it possible to reselect the same option already chosen and open the new app? Matlab doesn't seem to allow me to choose an option again that's already been chosen.

답변 (1개)

Saffan
Saffan 2023년 6월 27일
Hi Desmond,
I can understand that you want to re-select the same option from a drop-down menu. To allow re-selection of the same option, you can follow these steps:
  • Create a default option in the drop-down menu with no actions, such as ‘Select’.
Here is an example code snippet to create a drop-down menu and value changed callback function:
% Create DropDown
app.DropDown = uidropdown(app.UIFigure);
app.DropDown.Items = {'Select', 'app1', 'app2'};
app.DropDown.DropDownOpeningFcn = createCallbackFcn(app, @dropDownOpen, true);
app.DropDown.ValueChangedFcn = createCallbackFcn(app, @valueChanged, true);
app.DropDown.BackgroundColor = [1 1 1];
app.DropDown.Position = [467 361 100 22];
app.DropDown.Value = 'Select';
% Value changed function: DropDown
function valueChanged(app, event)
value = app.DropDown.Value;
if (strcmp(value,'Selected'))
%do nothing
elseif(strcmp(value,'app1'))
%open app
app1;
end
end
  • Reset the value to default option every time the drop-down menu is opened by using the drop-down opening callback function.
Here is an example code snippet of drop-down opening callback function:
% Drop down opening function:
function dropDownOpen(app, event)
app.DropDown.Value='Select';
end
Refer to this for more information:

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by