Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: list box-seletion via mouse

Subject: list box-seletion via mouse

From: Jason

Date: 8 May, 2008 09:50:19

Message: 1 of 2

Hi, if I have a list box populated by several items, is it
possible to get a particular item by using the mouse to
select that item (or get the index of the item - using the
mouse to select)?

thanks

Jason

Subject: list box-seletion via mouse

From: helper

Date: 8 May, 2008 10:08:05

Message: 2 of 2

"Jason " <Jbryant@illumina.com> wrote in message
<fvuicr$2tu$1@fred.mathworks.com>...
> Hi, if I have a list box populated by several items, is
it
> possible to get a particular item by using the mouse to
> select that item (or get the index of the item - using
the
> mouse to select)?
>
> thanks
>
> Jason

I'm not sure what you mean. I think what you want to know
about is how to define a "callback" for the listbox. Look
into setting the "Callback" function for the listbox
(search the doc for the term "Callback"). Then, whenever
you click the listbox, your callback function will run.

Within the callback function, you can read the "Value"
property of the listbox to tell what is the index of the
currently selected item. You can read the "String"
property of the listbox to get a list of all elements in
the listbox. Then you can index into the result
of "String" using "Value" to determine the selected element.

OK, some code. First, set the "Callback" property of your
listbox to be "@Listbox_Callback" (without the quotes).
Then, create a function named ListBox_Callback containing
the code:

function ListBox_Callback(hObj,eventdata,handles)
value = get(hObj,'Value'); % Index of selected item
string = get(hObj,'String'); % List of strings
selected = string{value}; % Selected string
...<more code>...

Now, you can do whatever you want with "value"
or "selected".

Good luck!

Tags for this Thread

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.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics