필터 지우기
필터 지우기

Resetting Pop up Menu

조회 수: 4 (최근 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 CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by