Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
William le 28 Jan 2013
Commenté : sait le 13 Mar 2014
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 commentaire
sait le 13 Mar 2014
ind = get(handles.listbox1,'value')
liste = get(handles.listbox1,'String')
liste(ind) = [];
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.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 28 Jan 2013
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 commentaires
William le 29 Jan 2013
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 le 29 Jan 2013
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.

Connectez-vous pour commenter.


En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by