Filter löschen
Filter löschen

Resetting Pop up Menu

1 Ansicht (letzte 30 Tage)
Adedeji
Adedeji am 30 Mär. 2014
Kommentiert: Image Analyst am 16 Jul. 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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 30 Mär. 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 Kommentare
david setiawan
david setiawan am 16 Jul. 2020
thanks bro!
Image Analyst
Image Analyst am 16 Jul. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by