필터 지우기
필터 지우기

Select a cell from a uitable using two edit boxes

조회 수: 22 (최근 30일)
telmo egues
telmo egues 2018년 8월 14일
댓글: Konvictus177 2022년 9월 27일
Hi, I'm working on a GUI and i would like to select a cell from an uitable using two edit boxes, one for the row and the second for the column instead of clicking directly on the cell, as the table is very big. I've tried several things with the CellSelectionCallback but haven't reached a solution.
Thanks in advance
  댓글 수: 2
Adam
Adam 2018년 8월 14일
Do you mean you actually want the cell of the uitable to be highlighted or you just want to select the data from that row/column?
CellSelectionCallback is triggered when you make a selection so doesn't seem like it would be useful to do either.
telmo egues
telmo egues 2018년 8월 16일
I mean just select the cell as if you selected it manually.
Thanks

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2018년 8월 14일
편집: Adam Danz 2021년 5월 10일
Matlab R2021a and later
Starting in Matlab R2021a, you can programmatically scroll to any row, column, or cell of a uitable using the scroll function (see Four New App Features in MATLAB R2021a).
Syntax examples:
Prior to R20201a
Here's a method to programmatically select a cell which highlights the chosen cell as if it were just selected manually. This requires FEX: findjobj(); credit to this answer .
% Create a working UI table for the example
f = figure;
t = uitable(f,'Data',randi(100,10,3),'Position',[20 20 262 204]);
% Select row and col numbers
row = 2;
col = 3;
% Select cell programmatically
jUIScrollPane = findjobj(t);
jUITable = jUIScrollPane.getViewport.getView;
jUITable.changeSelection(row-1,col-1, false, false);
If you're trying to act on that cell by applying a function to the cell's content, you might not have to actually highlight it and you could avoid the 3rd party function.
  댓글 수: 1
Adam Danz
Adam Danz 2019년 12월 6일
Note that this method does not work in app designer UI tables.
Also note that the findjobj() function uses the JavaFrame property and javacomponent function which will no longer be supported by Matlab in future releases.
More info:

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Mark Thomson
Mark Thomson 2021년 3월 25일
Hi, I just had this issue with a table in App Designer. Have buttons to shift rows, and want the "Selected Cells" range to move as well.
In the end, I chose to store the cell indices in an App property variable (here: 'selected_cell'), and use my own highlighting, as per (for a table called 'Par_Table')
function Par_TableCellSelection(app, event)
app.selected_cell = event.Indices; % App property variable
update_highlighted_cells(app);
end
function update_highlighted_cells(app)
removeStyle(app.Par_Table);
addStyle(app.Par_Table,app.highlighted_cell_style, ...
'cell',app.selected_cell);
end
after defining
app.highlighted_cell_style=uistyle('BackgroundColor','yellow');
Then you can update the values in 'app.selected_cell' in other callbacks and call 'update_highlighted_cells' again.
Seems to update fast enough for me. Maybe someone already posted this work-around and I didn't find it.
Regards, MT
  댓글 수: 2
Adam Danz
Adam Danz 2021년 3월 25일
+1
Thanks for the update, Mark Thomson
addStyle & removeStyle were added in r20219b.
Konvictus177
Konvictus177 2022년 9월 27일
Thanks!

댓글을 달려면 로그인하십시오.


Barbara Presley
Barbara Presley 2019년 1월 31일
I also need to highlight cells, and this solution didn't work for me. I installed the FEX: findobj(). jUIScrollPane = findjobj(t) did not produce anything. I exchaged t with f to see if findjobj worked at all. It did.
  댓글 수: 1
Adam Danz
Adam Danz 2019년 1월 31일
Is t the handle to your UI table? Share a snippet of your code.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by