App Designer DropDown Menu cannot select the first item

7 views (last 30 days)
I have inserted a DropDown Menu (TrialsListDropDown) in my GUI that I am creating with the App designer.
It is initialized in the startupFCN function as follows:
app.TrialsListDropDown.Items = cellstr(strings(5,1));
It is populated when the user selects the path of the file containing the strings to display as follows:
app.TrialsListDropDown.Value = "";
app.TrialsListDropDown.Items = app.CellTrialNames;
app.TrialsListDropDown.ItemsData = app.CellTrialNames;
The strings are correctly displayed in the DropDown Menu.
The selection of a DropDown item is caried out through a callback as follows:
% Value changed function: TrialsListDropDown
function TrialsListDropDownValueChanged(app, event)
value = app.TrialsListDropDown.Value;
app.SelectedTrial = app.TrialsListDropDown.Value;
disp(app.SelectedTrial) % DEBUG PURPOSE
end
So far the above callback contains just the code to extract the selected item and display it.
My problem is that the first DropMenu item cannot be selected. I have to select one of the other items and then go back to the first one.
I understand the callback is only triggered upon Value changed. I deduce the first listed item is by default the selected item.
How can I change this behaviour so that the user can select also the first item right away after the DropDown Menu is populated?
Thank you so much.
Maura (maura.monville@nhs.net)

Answers (1)

T.Nikhil kumar
T.Nikhil kumar on 17 May 2024
Hello Maura,
I get that you want to be able to call the ‘ValueChangedFcn’ when clicking on the default selected item in the dropdown.
Based on the name of the callback itself i.e. ‘ValueChangedFcn’, it makes sense that if the value of dropdown does not change, the callback should not fire. Hence, I do not think it is possible to call this function on selecting the default selected item.
However, as a hack, I would suggest you to introduce a dummy option in the dropdown and make it the default selected item so that you the ‘ValueChangedFcn’ would be called on selecting any of the other meaningful options.
You can introduce ‘-‘ as a new option in the dropdown. In the callback, you can perform the required operations only if some meaningful option is clicked.
Hope this helps you proceed with your work!

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!