Resetting Pop up Menu

2 ビュー (過去 30 日間)
Adedeji
Adedeji 2014 年 3 月 30 日
コメント済み: Image Analyst 2020 年 7 月 16 日
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.

採用された回答

Image Analyst
Image Analyst 2014 年 3 月 30 日
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 件のコメント
david setiawan
david setiawan 2020 年 7 月 16 日
thanks bro!
Image Analyst
Image Analyst 2020 年 7 月 16 日
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.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by