programmatical access to current selection in uitable under uifigure

48 次查看(过去 30 天)
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!


Xiangrui Li
Xiangrui Li 2020-9-20
编辑:Xiangrui Li 2020-9-20
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 个评论
Arabarra 2020-12-10
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.


更多回答(2 个)

David Hill
David Hill 2020-6-15
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);
function selection(src,event)
  1 个评论
Arabarra 2020-6-15
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.


Xiangrui Li
Xiangrui Li 2020-8-29
编辑:Xiangrui Li 2020-8-29
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 个评论
Walter Roberson
Walter Roberson 2020-8-30
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...



Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by