Filter löschen
Filter löschen

Add new DropDown item in App designer 2019a

37 Ansichten (letzte 30 Tage)
CamPe
CamPe am 3 Mai 2020
Kommentiert: CamPe am 11 Mai 2020
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

Akzeptierte Antwort

Tommy
Tommy am 3 Mai 2020
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?

Weitere Antworten (0)

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by