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

24 views (last 30 days)
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 Comment
Geoff Hayes
Geoff Hayes on 27 Jun 2022
@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.

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 27 Jun 2022
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 Comments
Akana Juliet
Akana Juliet on 28 Jun 2022
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?

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!