Azzera filtri
Azzera filtri

Resetting Pop up Menu

1 visualizzazione (ultimi 30 giorni)
Adedeji
Adedeji il 30 Mar 2014
Commentato: Image Analyst il 16 Lug 2020
I just ran accross an annoying issue with pop-ups in GUIs. If you create a list of items in a popup, then change the 'String' property to display a new shorter list, you must reset the 'Value' property (which points to the string in the list to display) manually. If you don't,
and the Value property is no longer valid, an annoying error occurs which is not covered well in the help. For example, if old list had 5 items with Item # 5 selected, Value = 5. Now if you set the String property to a 3 element array, Value is not automatically reset and now exceeds the range of the string array. The control will not be drawn
and a cryptic error message 'Value must be set to a valid string integer...' or something like that is displayed. Very annoying. I couldn't find a reference to this in the on-line or website help.

Risposta accettata

Image Analyst
Image Analyst il 30 Mar 2014
Yes, that's true. I guess it would be nice if it automatically reset the value to the max if it recognized that instead of throwing an error, but it doesn't. By the way, it's the same for listboxes and sliders too. So if you ever fill a listbox with filenames and then push a button to specify a different folder, you need to set the value to null or 1.
  5 Commenti
david setiawan
david setiawan il 16 Lug 2020
thanks bro!
Image Analyst
Image Analyst il 16 Lug 2020
The new way to do it, since R2014b (September 2014) would be:
set(handles.listbox1, 'Value', []);
handles.popup1.Value = 1;
I think for some reason you can't unselect all items in the listbox by doing
handles.listbox1.Value = [];
If I remember correctly that throws an error but I believe the set version still works. However for almost all other situations it's simpler and preferable to use the OOP way and not to use the set() way, like I did for setting the popup selection to 1.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by