Is it possible to allow a re-selection of the same option from a drop down menu?
1 次查看(过去 30 天)
显示 更早的评论
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
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:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!