programmatical access to current selection in uitable under uifigure

48 ビュー (過去 30 日間)
Arabarra
Arabarra 2020 年 6 月 15 日
コメント済み: Arabarra 2020 年 12 月 10 日
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

採用された回答

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
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);
uit.CellSelectionCallback=@selection;
function selection(src,event)
k=event.Indices
end
  1 件のコメント
Arabarra
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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by