Interaction between two list box problem

조회 수: 1 (최근 30일)
Paul
Paul 2011년 10월 14일
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.

채택된 답변

Fangjun Jiang
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:
  1. What if listbox1 and/or listbox2 is empty?
  2. What if listbox1 and/or listbox2 becomes empty?
  3. What if listbox1 and/or listbox2 contains duplicated item?
Function isempty() and unique() can help.
  댓글 수: 1
Paul
Paul 2011년 10월 15일
Ah of course, as the value was still set at 4 it was trying to select the 4th element while there was only 3 left. Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by