Clear Filters
Clear Filters

How to specify a callback function for the CellSelectionCallback property for runtime created Tables in App Designer?

2 views (last 30 days)
In App Designer:
Suppose that a TabGroup is created in App Designer's Design View, and that new tabs are simply added at runtime:
hTab = uitab(app.TabGroup,'Title',name_string);
Then suppose that a table is created as a child of the new tab, with a function specified for the CellSelection callback:
hTable = uitable(hTab,'CellSelectionCallback',@TableCellSelection);
The function TableCellSelection(app,event) is a private method in the app.
When the user selects some region of a successfully populated table, the following error results:
Undefined function 'TableCellSelection' for input arguments of type 'matlab.ui.control.table'.
Am I using an incorrect approach, or is this possibly a bug? Thanks.

Answers (1)

Kevin Holly
Kevin Holly on 26 Jul 2023
It seems like MATLAB cannot locate the function. You could call the function from outside the app. Please see the app and script attached.
In the example attached, I called the function with app as an input:
hTable = uitable(hTab,'CellSelectionCallback',{@TableCellSelection app});
To test to see if the function works, I had it make a label visible.
function TableCellSelection(table_handle,events,app)
app.CellSelectionworksLabel.Visible = "on";


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!