필터 지우기
필터 지우기

Resetting Listbox handle 'value' to prevent warning and dissappearing of listbox on GUI

조회 수: 2 (최근 30일)
William
William 2013년 1월 28일
댓글: sait 2014년 3월 13일
If I push a button on my GUI to generate an external figure my listbox dissapears on my GUI and I get this warning.
I am recalling setappdata() used elsewhere in the code
Warning: single-selection listbox control requires that Value be an integer within String range
Control will not be rendered until all of its parameter values are valid
The reaseon I get this warning is that on one radio button I import two strings making the handles.listbox3, 'value') = 2 the others it equals '1' If I select the second (bottom) string and change radio button the listbox dissapears because the maximum number of strings sent to the listbox is now 1 and two is outside the bounds. I have tried this at the begining of every point in the switch:
plot_selected = get(handles.listbox3, 'value')
plots_allowed = get(handles.listbox3, 'string')
data_2_plot = plots_allowed(plot_selected,:)
or I've tried this
set(handles.listbox3, 'value', 1)
Neither work. Does anyone else have a cleaver way to reset the 'value' handle of the listbox?
Thank you!
  댓글 수: 1
sait
sait 2014년 3월 13일
ind = get(handles.listbox1,'value')
liste = get(handles.listbox1,'String')
liste=cellstr(liste)
liste(ind) = [];
set(handles.listbox1,'String',liste);
set(handles.listbox1,'value',1) % it is purpose to slect first item in listbox
set(handles.listbox1,'visible','on') % if last element of listbox is delete then sometimes listbox is not visible on the gui. For this reason listbox have to update.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2013년 1월 28일
Somehow, the Value of that listbox has become a non-integer (e.g., fraction or []), or become an integer that is not positive, or now exceeds the number of String in the listbox.
  댓글 수: 2
William
William 2013년 1월 29일
I tried using set(handles.listbox3, 'value',1);
But it does not seem to work. Any suggestions as to how to reset the value of the list box to 1? Thank you!
Walter Roberson
Walter Roberson 2013년 1월 29일
Each time you set the String property of the listbox, also set the Value property to 1.
I also recommend you switch away from setting the String property to character arrays, and instead set the String property to a cell array of strings.
set(handles.listbox3, 'String', {'We are the champions', 'of the workd'}, 'Value', 1);
when you retrieve, use
data_2_plot = plots_allowed{plot_selected};
and then no need to trim trailing blanks off of it.

댓글을 달려면 로그인하십시오.

카테고리

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