Thread Subject: GUI Implementation

Subject: GUI Implementation

From: Matlab Morisetti

Date: 3 Jun, 2009 13:03:01

Message: 1 of 4

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.

Subject: GUI Implementation

From: John

Date: 4 Jun, 2009 14:13:02

Message: 2 of 4

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.

Subject: GUI Implementation

From: Matlab Morisetti

Date: 5 Jun, 2009 05:39:01

Message: 3 of 4

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.

Subject: GUI Implementation

From: John

Date: 5 Jun, 2009 13:22:01

Message: 4 of 4

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.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
gui listbox Praveen Kumar Morisetti 5 Jun, 2009 01:44:04
listbox John 4 Jun, 2009 10:14:08
listbox in guis Praveen Kumar Morisetti 3 Jun, 2009 09:04:06
rssFeed for this Thread

Contact us at files@mathworks.com