programmatical access to current selection in uitable under uifigure

38 views (last 30 days)
Hi,
Is there any way to:
1) check which cells are currently selected in a uitable (under the new uifigures, I'm aware of the methods available for standard figures).
2) programmatically impose a selection...
Any comment welcome!
Daniel

Accepted Answer

Xiangrui Li
Xiangrui Li on 20 Sep 2020
Edited: Xiangrui Li on 20 Sep 2020
As mentioned in my previous post, Mathworks informed me the issue has been addressed since R2020a, but I did not find any documentation for it, neither in R2020b. After some hacks, it turns out they indeed addressed the issue, but those related properties are hidden and unavailable in the help document.
Here are several related properties (all hidden till R2020b):
h = uitable(uifigure, 'Data', magic(3)); % set up a table
h.Selection = [1 2]; % select a cell programmatically
h.SelectionType % default 'cell', could be 'row' or 'column'
h.Multiselect % default 'on', could be 'off', but will interact with SelectionType
Note if h.SeletionType is 'row', h.Selection, as well as event.Indices in callback, will be scalar.
  1 Comment
Arabarra
Arabarra on 10 Dec 2020
Wonderful! Thanks, Xiangrui!
I'm still on 2020a, so that I could not see the hidden properties. If they have more hidden goodies, I hope they reveal them soon.

Sign in to comment.

More Answers (2)

David Hill
David Hill on 15 Jun 2020
This shows how to show or assign the current indices selected. Not sure if you can programmatically impose selection. It appears that Indices is read only.
t = readtable('patients.xls');
vars = {'Age','Systolic','Diastolic','Smoker'};
t = t(1:15,vars);
fig = uifigure;
uit = uitable(fig,'Data',t);
uit.CellSelectionCallback=@selection;
function selection(src,event)
k=event.Indices
end
  1 Comment
Arabarra
Arabarra on 15 Jun 2020
thanks David. In my CellSelectionCallback I have added a line that stores the data of the last selection (as read from the event), so that I can access it from outside of the callback. It solves my problem, although it is still annoying.
For 2)... well, there is no obvious way to do this, I was wondering if somebody has found some backdoor, in the fashion that Yair Altman's jtable used to extend the usability of uitable in the standard figures.

Sign in to comment.


Xiangrui Li
Xiangrui Li on 29 Aug 2020
Edited: Xiangrui Li on 29 Aug 2020
In R2019b or earlier, there is no way to programmatically select a cell or row. This was confirmed with Mathworks and I requested the feature on October 20, 2019.
I tried a dumb way to simulate the selection: use uistyle to highlight a row of interest, and construct event.Indices for a call to CellSelectionCallback. It kind of works, except that the previously really selected row still has light blue background.
On August 28, 2020, I got a notice form Mathworks: “We are pleased to inform you that the issue you reported has been addressed in the R2020a release.”
But I did not find any related information in the online documentation for 2020a.
Given the date they notified me (long after R2020a release), I am guessing it means the issue is addressed in the upcoming R2020b release (expected September 2020). Hope to see the solution soon.
  1 Comment
Walter Roberson
Walter Roberson on 30 Aug 2020
They actually do mean R2020a. But sometimes it can be pretty difficult to find the information. And sometimes their idea of what it means for an issue to have been addressed is very different from our ideas.
For example I made a recommendation that the special handling of sym('pi') as becoming the symbolic constant π be documented. They did address the issue... they disabled that behavior, and now sym('pi') just becomes an ordinary variable that happens to be named pi and you have to use sym(pi) to get the symbolic constant .
This offends my sensibilities, relying as it does on the fact that sym(pi) will go through a conversion routine that does a series of tests against known values to determine that 3.141592653589793115997963468544185161590576171875 (the exact value stored for the numeric function named pi) happens to be "close enough" to π to be rounded to π .
But, I gotta admit, they did address the issue...

Sign in to comment.

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!