|
You can either remove the selected parameter from the left listbox once the paramter has been added to the right list or you can do a string comparision before adding to the right list and add item only if its not there already.
1) Removing selected paramater -
leftlist = cellstr(get(handles.listbox1,'String'));
index = get(handles.listbox1,'Value');
selected_item = leftlist{index};
rightlist = cellstr(get(handles.listbox2,'String'));
rightlist{end+1} = selected_item;
set(handles.listbox2,'String',rightlist);
leftlist(index) = [];
set(handles.listbox1,'String',leftlist)
2) Checking if item has already been added
leftlist = cellstr(get(handles.listbox1,'String'));
index = get(handles.listbox1,'Value');
selected_item = leftlist{index};
rightlist = cellstr(get(handles.listbox2,'String'));
if ~any(strcmp(rightlist,selected_item))
rightlist{end+1} = selected_item;
set(handles.listbox2,'String',rightlist);
end
To remove/erase parameter , in the erase button callback, you will have to get the current selected item and the entire list of strings. Then you will just have to do rightlist(index) = [] and set the 'String' property back to rightlist (Like in (1) above)
"Matlab Morisetti" <praveen.subscription@gmail.com> wrote in message <h0ab1l$g07$1@fred.mathworks.com>...
> Thanks John,
>
> Your method of implementation is optimistic and useful. By your code i am able to load the lb2* by selecting a parameter from the lb1*. But i am looking for some more enhancement like a parameter can be selected only once, i.e. even though i click same parameter for more than 1 time the lb2* should contain it for once. And also i have one more button (<) to erase the parameter from the lb2*.
>
> *lb1 - listbox1
> lb2 - listbox2
>
>
> "John" <sjohn@cnbc.cmu.edu> wrote in message <h08kpe$k2i$1@fred.mathworks.com>...
> > In the callback routine for your pushbutton, get the item selected from the left listbox and insert it into the right listbox.
> >
> > leftlist = cellstr(get(handles.listbox1,'String'));
> > index = get(handles.listbox1,'Value');
> > selected_item = leftlist{index};
> > rightlist = cellstr(get(handles.listbox2,'String'));
> > rightlist{end+1} = selected_item;
> > set(handles.listbox2,'String',rightlist);
> >
> > Here 'listbox1' and 'listbox2' should be the values of the 'tag' property of the left and right listboxes respectively.
> >
> > "Matlab Morisetti" <praveen.subscription@gmail.com> wrote in message <h05sa5$pae$1@fred.mathworks.com>...
> > > Hi Everybody,
> > >
> > > I am working on GUIs to build a front end for the BMS (battery management system).
> > > In the process i came across implementing the List box. In brief, I have '>' pushbutton between two listboxes of which left (listbox1) one holds the list of items and the right (listbox2) one holds the selected items from listbox1. So i am stucked up with the implementation. Can anyone provide me with some help regarding this issue.
|