How to uncheck all other checkboxes when one is selected in App Designer Table

5 views (last 30 days)
I have a UITable in App Desinger. The first column is logical and therefore displays editable checkboxes. My objective is to have all other checkboxes cleared (unchecked) after I select a single check box. My current section of code is the following:
% Callbacks that handle component events
methods (Access = private)
% Cell edit callback: UITable
function UITableCellEdit(app, event)
% If the edited column is the checkbox column
if event.Indices(2) == 1
% Uncheck other checkboxes in the column after selection
if event.NewData
app.UITable.Data(:, 1) = {false};
end
app.UITable.Data{event.Indices(1), 1} = event.NewData; % Check the clicked checkbox
end
end
end
However, when I run the app I can still have multiple checkboxes selected at a time. This is not my intended effect. Again, I only want one checkbox to be able to be selected at a time; when one is selected all others should be cleared.
  1 Comment
Joshua
Joshua on 3 May 2024
% Cell edit callback: UITable
function UITableCellEdit(app, event)
% If the edited column is the checkbox column
if event.Indices(2) == 1
% Uncheck other checkboxes in the column after selection
if event.NewData
app.UITable.Data(:, 1) = {false};
end
app.UITable.Data{event.Indices(1), 1} = event.NewData; % Check the clicked checkbox
end
end

Sign in to comment.

Accepted Answer

Joshua
Joshua on 3 May 2024
I had to ensure the startupFcn contained the following line, associated with the correct component name:
% Set the callback function for cell editing
app.UITable.CellEditCallback = @(src, event) UITableCellEdit(app, event);

More 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!