UITable CellSelectionCallBack is not triggering when same cell is selected

4 views (last 30 days)
I have an app in App Designer that is running a CellSelectionCallBack function, but one of the actions I want to use is to move values in the table. If I select a row in the table, click the button to move it and then click the same row again, CellSelectionCallBack function doesn't execute. (There's a down button also with the same idea to move rows down.
% Cell selection callback: UITable_2
function UITable_2CellSelection(app, event)
app.UITable2Selected = event.Indices;
end
I change the selected file variable to follow the after the move in case the user wants to keep moving thw same file up.
% Button pushed function: up
function upPushed(app, event)
% Does nothing if the UITable_2 is empty or the selected value is already at the top.
if ~isempty(app.UITable_2.Data) && app.UITable2Selected(1)>1
% swap rows to move selected row up in UITable_2
a = app.UITable_2.Data(app.UITable2Selected(1),:);
b = app.UITable_2.Data(app.UITable2Selected(1) - 1,:);
app.UITable_2.Data(app.UITable2Selected(1),:) = b;
app.UITable_2.Data(app.UITable2Selected(1) - 1,:) = a;
% swap rows to move selected row in UITable_2 for Datapaths
a = app.DataPaths(app.UITable2Selected(1),:);
b = app.DataPaths(app.UITable2Selected(1) - 1,:);
app.DataPaths(app.UITable2Selected(1),:) = b;
app.DataPaths(app.UITable2Selected(1) - 1,:) = a;
% change the selected value to follow target file
app.UITable2Selected(1) = app.UITable2Selected(1) - 1;
end
end
If I click the same row after clicking the up button, Is there any way to reset and let it trigger a new selection even if the user selects the last row selected?
  1 Comment
Jan
Jan on 10 Nov 2022
Edited: Jan on 10 Nov 2022
% In case you have SelectionType set to 'cell' then at the end of the function you can change it to other type (e.g. 'row') and then change it back right away. This will deselect the clicked cell and allow you to click on it again. The disadvantage of this approach is that you cannot use keyboard to navigate thru the cells. Therefore, it is only helpful if you use mouse to click on the cells.
app.UITable_2.SelectionType = 'row'; pause(0.01); % I am not sure if the pause is necessary
app.UITable_2.SelectionType = 'cell';

Sign in to comment.

Answers (0)

Categories

Find more on Develop Apps Using App Designer 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!