[GUI] How can I pass only ONE signal at a time from TWO lisboxes to the third one?

조회 수: 1 (최근 30일)
dyyyyyl
dyyyyyl 2016년 1월 11일
댓글: Image Analyst 2016년 1월 11일
Hi All,
I'm working on a GUI and it has altogether 3 listboxes. Items listed in Listbox 1 or 2 can be secleted into Listbox 3 by clicking a pushbutton ''ADD''. Here's the code: ..........................................................................................................................................
if(items_in_L3==0) %%%no items in listbox3
L3_List = [signal_name,'_L1'];
%%to identify whether the item comes from Listbox1 or 2
L3_List2 = [signal_name2,'_L2'];
L3_List_sum = {L3_List, L3_List2};
elseif(items_in_L3==1) %%%one item already existed in listbox3
L3_List{1} = signal_names;
%signal_names=get(listbox3,'String')%%the item in listbox3
L3_List{2} = [signal_name,'_L1'];
L3_List{3} = [signal_name2,'_L2'];
L3_List_sum = L3_List;
else
L3_List = signal_names;
L3_List{items_in_L3+1} = [signal_name,'_L1'];
L3_List{items_in_L3+2} = [signal_name2,'_L2'];
L3_List_sum =L3_List;
end;
set(listbox3, 'String', L3_List_sum);
..........................................................................................................................................
And here comes the problem, sometimes I only want to choose items(or signals) from Listbox1, not 2, vice versa. With the code above I must choose signals from both Listbox1 and 2 every time. Is there some way that allow me to choose the item in THE Listbox, that I just clicked or activated? (not both at the same time). Thx for your help! :)

답변 (1개)

Image Analyst
Image Analyst 2016년 1월 11일
There are a variety of ways you can do this. I would have a button below each listbox that says "Put in Listbox3". Then they just click on whichever one they want. If you want you could have a third button that says "Put both into Listbox3" so they can click once instead of twice. The other option is to have checkboxes and just one button and they can set the checkbox status (for which listbox(es) they want to send over) and then click the single button.
If you want to send the item over immediately upon clicking, then you can just put the code into each listbox's callback to send it over immediately.
For any method, you might want to call unique() to make sure that an item does not get sent over multiple times (for example, like if you're clicking multiple times). Or, if you're doing the immediate send via the listbox callbacks) you could just make the listbox single selection and then after it's sent over, clear the selection by doing set(handles.listbox1, 'Value', []).
  댓글 수: 2
dyyyyyl
dyyyyyl 2016년 1월 11일
Hello, thank you for your reply! This does work, however I already got too many components in my GUI, and sent items over immediately upon clicking may be a little inconvenient in my case, since there are many signals in listboxes 1 and 2. A misoperation is likely to happen.
Is it possible to achieve this by using ButtonDownFcn?
Image Analyst
Image Analyst 2016년 1월 11일
In the ButtonDownFcn for which control? If you don't want any more controls on the GUI, then I suggest you just send over the item immediately upon clicking like I suggested second. Just put the code in the listbox callback function.

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by