uitable in AppDesigner: cell edit callback and cell selection callback execute simultaneously

Hello!
I'm creating a GUI with an editable table in ML2019. I want to select a part of that table and when I enter a new value, it should be written to all selected cells (just like one knows it from MS Excel or others).
To achieve this, I programmed a cell selection callback that stores the indices of the selected cells in a global variable that can be used in the cell edit callback function.
When I edit one of the selected cells and finish with <ENTER>, the cell edit callback is called, the eventdata argument holds the new value and the edited cell (and some other data) and my global variable holds the complete selection of cells. The new value is then copied to all selected cells, identified by my global variable. Everything's fine.
Now, when I do the same thing but finish the editing not with <ENTER> but by selecting another cell of the table, the new value is not written to the first selection but to the cell I selected to finish the editing. Meanwhile I found out, that both callback functions seem to be called simultaneously. But cellSelectCallback is faster, stores the new selection to my global variable and when the cellEditCallback uses the selection to write the new value, it gets the index of the new selection.
Is there a smarter way to avoid this behaviour? Maybe using global variables is not the best way but what else?

3 Comments

I don't have R2019b, but I can confirm this behavior in R2016b, and I observe that the problem appears to be fixed by R2023b (i.e., clicking the table behaves the same as pressing <ENTER> (or <TAB>); btw, <TAB> works the same as <ENTER> in those two versions).
Here's the code I use to test:
function main_GUI()
f = uifigure();
t = uitable(f, ...
'Data',magic(4), ...
'ColumnEditable',true, ...
'CellSelectionCallback',@csc_fcn, ...
'CellEditCallback',@cec_fcn);
selected_cells = [];
function csc_fcn(~,evt)
selected_cells = evt.Indices;
end
function cec_fcn(~,evt)
for ii = 1:size(selected_cells,1)
t.Data(selected_cells(ii,1),selected_cells(ii,2)) = evt.NewData;
end
end
end
Given @Voss's confirmation of the bug, it would seem upgrading would be the better solution, but to the "what else to do" in R2019b I note the following caveat in the <table properties callbacks documentation>
CellSelectionCallbackCell selection callback function
function handle | cell array | character vector
Note
This property is not recommended for tables in App Designer or in apps created using the uifigure function. In uifigure-based apps, to execute commands when the app user selects different elements of the table, use the SelectionChangedFcn property instead.
@dbp:
Unfortunately due to my company's development rules, I can't simply upgrade the Matlab version, still need to stick to 2019b for a while.
The documentation (your link) is from 2024. In the docu of 2019 this limitation is not yet mentioned. And also, the SelectionChanged property does not exist in 2019, so I can't use it.
@everyone, who might be interested in this issue:
Nevertheless, I found a very simple workaround solution that works perfect for me. I simply added a 10ms pause in the CellSelection-Callback. That gives the CellEdit-Callback enough time to finish its work before CellSelection is executed and does not annoy the user too much. The 10ms may vary depending on processor speed and complexity of the CellEdit-Callback.

Sign in to comment.

Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2019b

Asked:

on 19 Mar 2025

Commented:

on 20 Mar 2025

Community Treasure Hunt

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

Start Hunting!