필터 지우기
필터 지우기

App Designer DropDown Menu cannot select the first item

조회 수: 7 (최근 30일)
Maura Monville
Maura Monville 2022년 5월 18일
답변: T.Nikhil kumar 2024년 5월 17일
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)

답변 (1개)

T.Nikhil kumar
T.Nikhil kumar 2024년 5월 17일
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!

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by