Interaction between two list box problem

5 次查看(过去 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.

采纳的回答

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