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!