How to clear all EditFields in App Designer that were dynamically generated

21 ビュー (過去 30 日間)
Hi everyone, thanks for taking the time to read my question. I am still a novice, so please forgive me.
I am making a GUI that reads in data from a yaml file, presents it to the user in edit fields, and the user will be able to modify the values.. So when the user selects a type in the dropdown menu, the callback function dynamically generates Edit Field Labels and Edit Fields using the yaml data.
I used this very helpful answer to generate the EditFields/Labels:
I was able to sucessfully import the data how I needed to. The only problem is that the yaml struct fields are not all the same across different types, so if the user selects a type in the dropdown menu again, the callback function just generates labels on top of the space that was already used.
I either need a way to reset the GUI to exactly how it is when the GUI is launched (I tried a 'Clear All' button as seen below, but it does not work)
or I might need a way to check if the Labels are the same, and if they are not, clear the Label instead of writing on top of it.
Any help would be greatly appreciated! Thank you!
function ClearProfileButtonPushed(app, event)
startupFcn(app)
drawnow;
figure(app.UIFigure)
end
  1 件のコメント
Geoff Hayes
Geoff Hayes 2022 年 6 月 27 日
@Akana Juliet - we would probably need to see the code that you have written that creates the edit fields, but I suspect that since you are dynamically creating them (if I read this correctly), then you can just delete them when needed.

サインインしてコメントする。

採用された回答

Cris LaPierre
Cris LaPierre 2022 年 6 月 27 日
The code you need is in the solution you link to.
% delete all labels and edit fields
delete(app.TypeOfPlyLabels);
delete(app.TypeOfPlyEdidFields);
I tested by creating an app using the code in the solution you linked to. Then to test deleting the added Edit fields, I added button and pasted the above code in its callback. Runnnig the script would create a predefined number of edit fields. Then clicking the button would remove just the ones that had been added dynamically.
  2 件のコメント
Akana Juliet
Akana Juliet 2022 年 6 月 28 日
Hi Cris, thanks so much for your response. I've tried this and it doesn't clear every single row, so I'm confused. I made a button to delete(app.____); and also put it in the callback function. Do you know what else I could try?
Cris LaPierre
Cris LaPierre 2022 年 6 月 28 日
Share your app

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by