MATLAB Answers

How to get indices of selected uitable cell outside cellselection callback

162 views (last 30 days)
Kunal Singhal
Kunal Singhal on 31 Oct 2017
Commented: Maryam Abbaszadeh on 14 Sep 2020
I have a uitable in appdesigner with a struct array containing some elements from the table and some additional elements that I do not display in the table. I want to make changes to any of these elements after a press a button. I am trying to get the index/ data of the selected cell in the table which will help me locate them in the structure and then update the changes. Since there is no getselected function, how to get this index outside the cellselectioncallback without having to add additional column with check box

  0 Comments

Sign in to comment.

Answers (1)

Mary Abbott
Mary Abbott on 3 Nov 2017
Hello,
To accomplish this, you can create a property in your app that will store the currently selected indices. Then, add a cellSelectionCallback that updates this property every time a new cell is selected. This would look something like:
% (Add selectedCell property to store indices)
% Cell selection callback: UITable
function UITableCellSelection(app, event)
app.selectedCell = event.Indices;
end

  3 Comments

Eduardo Gaona Peña
Eduardo Gaona Peña on 7 Feb 2018
I'm trying something like this but my callback is not returning any value :( (see attached screenshot)
% Cell selection callback: UITable
function UITableCellSelection(app, event)
event.Indices
end
Petar Zuvela
Petar Zuvela on 30 Apr 2018
Actually, add a selection callback for your table and then copy the code below into it:
app.selectedCell = event.Indices;
Of course, don't forget to define selectedCell as a property.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by