Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Desmond Harris
Desmond Harris le 12 Mai 2023
Réponse apportée : Saffan le 27 Juin 2023
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.

Réponses (1)

Saffan
Saffan le 27 Juin 2023
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:

Catégories

En savoir plus sur App Building dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by