- What if listbox1 and/or listbox2 is empty?
- What if listbox1 and/or listbox2 becomes empty?
- What if listbox1 and/or listbox2 contains duplicated item?
Interaction between two list box problem
조회 수: 1 (최근 30일)
이전 댓글 표시
I have two list boxes, one with some data and the other empty. I have two buttons, one to add data from one to the other and the other does the same but in the opposite direction. When the data gets moved across it gets removed from the original list box.
numm=get(handles.listbox1,'Value')
list1=get(handles.listbox1,'String');
list2=get(handles.listbox2,'String');
set(handles.listbox2,'String',[list2;list1(numm)]);
list1(numm,:) = []
set(handles.listbox1,'String',list1);
For example if my listbox had 4 lines of data in it, I can select any of the first three and move it over, but if I select the 4th bit of data first and move it across I get the error
"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 "
I'm not sure why this is happening.
댓글 수: 0
채택된 답변
Fangjun Jiang
2011년 10월 14일
When you eliminate one item in the string of listbox1 and update the string of listbox1, you didn't update the 'value' of listbox1.
For example, at the beginning, listbox1 has 4 items, the 4th item is selected. After you remove the 4th item, there are 3 items in listbox1, but the 'value' is still 4.
To make your program robust, consider and test out the following:
Function isempty() and unique() can help.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!