Add new DropDown item in App designer 2019a

37 次查看(过去 30 天)
Im new in Matlab, and Im trying to add a new item to the existing dropdown items, from an EditField text value, but I havent find out how, this is what Im doing, but Im not sure how to finish it:
function EditFieldValueChanged(app, event)
new = app.EditField.Value;
hDropDown = app.DropDown;
currentItems = get(hDropDown);
[~, index] = ismember(hDropDown.Value, hDropDown.Items);
newItems = {currentItems,new};
newItems(index) = [];
end

采纳的回答

Tommy
Tommy 2020-5-3
This will add the edit text's string to the drop down's list of items as long as it is not already there:
function EditFieldValueChanged(app, ~)
new = app.EditField.Value;
if ~any(ismember(app.DropDown.Items, new))
app.DropDown.Items = [app.DropDown.Items new];
end
end
Is this what you're looking for?

更多回答(0 个)

类别

Help CenterFile 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!

Translated by