Thread Subject: Get selected cells in a table

Subject: Get selected cells in a table

From: Claire Lee

Date: 17 Apr, 2011 10:50:04

Message: 1 of 5

Hello,
Anybody knows how to get selected cells (row and column indices) in a uitable? Thanks.

Subject: Get selected cells in a table

From: Claire Lee

Date: 18 Apr, 2011 23:52:04

Message: 2 of 5

Anyone has an idea? When a number of cells in a uitable are selected, how do I get their row and column indices in my program?

Thanks.

Subject: Get selected cells in a table

From: Pekka Teppola

Date: 5 Oct, 2011 07:22:10

Message: 3 of 5

I have the same question. Is there anyone out there with a solution? Thank you in advance.


"Claire Lee" <r91942001@ntu.edu.tw> wrote in message <ioiir4$1u8$1@fred.mathworks.com>...
> Anyone has an idea? When a number of cells in a uitable are selected, how do I get their row and column indices in my program?
>
> Thanks.

Subject: Get selected cells in a table

From: matt dash

Date: 5 Oct, 2011 17:54:29

Message: 4 of 5

"Pekka Teppola" wrote in message <j6h0j2$fl4$1@newscl01ah.mathworks.com>...
> I have the same question. Is there anyone out there with a solution? Thank you in advance.
>
>
> "Claire Lee" <r91942001@ntu.edu.tw> wrote in message <ioiir4$1u8$1@fred.mathworks.com>...
> > Anyone has an idea? When a number of cells in a uitable are selected, how do I get their row and column indices in my program?
> >
> > Thanks.


First you download findjobj from the file exchange. Then...

figure
u=uitable('data',magic(10))
uu=findjobj(u)
rows=uu.getComponent(0).getComponent(0).getSelectedRows+1
cols=uu.getComponent(0).getComponent(0).getSelectedColumns+1

Subject: Get selected cells in a table

From: Sven

Date: 5 Oct, 2011 20:38:10

Message: 5 of 5

"matt dash" wrote in message <j6i5kk$h16$1@newscl01ah.mathworks.com>...
> "Pekka Teppola" wrote in message <j6h0j2$fl4$1@newscl01ah.mathworks.com>...
> > I have the same question. Is there anyone out there with a solution? Thank you in advance.
> >
> >
> > "Claire Lee" <r91942001@ntu.edu.tw> wrote in message <ioiir4$1u8$1@fred.mathworks.com>...
> > > Anyone has an idea? When a number of cells in a uitable are selected, how do I get their row and column indices in my program?
> > >
> > > Thanks.
>
>
> First you download findjobj from the file exchange. Then...
>
> figure
> u=uitable('data',magic(10))
> uu=findjobj(u)
> rows=uu.getComponent(0).getComponent(0).getSelectedRows+1
> cols=uu.getComponent(0).getComponent(0).getSelectedColumns+1

A little hack not needing findjobj:
The problem is that the only time the selection indices are available is in the "CellSelectionCallback" function, which only gets triggered when the selection was originally made. All I do is re-route that callback to store the result in "UserData" as follows:

f = figure('Position', [100 100 752 350]);
t = uitable('Parent', f, 'Data', cell(3,5), 'Position', [25 25 700 200],'CellSelectionCallback',@(src,evnt)set(src,'UserData',evnt.Indices))

>> get(t,'UserData')

ans =

     []

% Make a table selection...

>> get(t,'UserData')

ans =

     1 2
     2 2
     2 4

Thanks,
Sven.

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

Contact us at files@mathworks.com