Updating listbox when deleting items
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I am currently creating a GUI with GUIDE on MATLAB 2010 and I have a rather strange issue. I have two listbox (listbox1 and listbox2) and when pressing "enter" when focus on listbox1, said item appears in listbox2 (cell array and use of "unique" to avoid duplicate). listbox1 is not altered. Then, by pressing "enter" with focus on listbox2, I delete said item from listbox2. So, being a newbie, I had at first the notorious "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 "
So I add some code to set Value at 1.
And then it became strange. The code works perfectly fine when I am doing it step by step on the debug tool, but as soon as I go back to normal, the warning re-appears.
Here is my code:
if strcmp(eventdata.Key, 'return')
handles.exp_names = handles.exp_names(~strcmp(handles.exp_names,handles.exp_deletion));
set(handles.listbox2,'Value',1);
refreshdata(handles.listbox2);
set(handles.listbox2,'String',handles.exp_names);
set(handles.listbox1,'visible','on')
guidata(hObject,handles);
end
Any idea of why this happens ?
Thank you
Vincent
0 Kommentare
Akzeptierte Antwort
Jan
am 9 Nov. 2017
The error message occurs, if the Value is not inside the range [1:numel(handles.exp_names)]. If you delete the last string from the list box, setting the value to 1 is an error.
I do not know, why this works in debug mode and fails without it. Perhaps there is another listbox in the figure, which has an invalid Value?
4 Kommentare
Jan
am 11 Nov. 2017
A pause can in fact solve a problem here, because it triggers the update of the GUI elements. The the position after the change of handles.exp_names does not really matter. All you must ensure, is that the display is not updated by pause, drawnow or a stop in the debugger, as long as 'String' and 'Value' are not corresponding. Therefore I'd prefer to update both properties in the same command:
set(handles.listbox2, 'Value', v, ...
'String', handles.exp_names);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!