|
"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.
|