Resetting Listbox handle 'value' to prevent warning and dissappearing of listbox on GUI
1 回表示 (過去 30 日間)
古いコメントを表示
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
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
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 件のコメント
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 Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!