Borrar filtros
Borrar filtros

Resetting Pop up Menu

1 visualización (últimos 30 días)
Adedeji
Adedeji el 30 de Mzo. de 2014
Comentada: Image Analyst el 16 de Jul. de 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.

Respuesta aceptada

Image Analyst
Image Analyst el 30 de Mzo. de 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 comentarios
david setiawan
david setiawan el 16 de Jul. de 2020
thanks bro!
Image Analyst
Image Analyst el 16 de Jul. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by