Create your own CellEditcallback
for your table.
Take the following example:
function testcode
% Initialize a basic GUI
h.myfig = figure;
% Initialize a dummy table
cnames = {'a','b'};
cformat = {'char', 'logical'};
rnames = {'1','2'};
mydata = {'firstfile', false; 'secondfile', false};
h.mytable = uitable( ...
'Parent', h.myfig, ...
'CellEditCallback', @boxchecked, ...
'ColumnFormat', cformat, ...
'ColumnName', cnames, ...
'ColumnEdit', true, ...
'RowName', rnames, ...
'Data', mydata ...
);
guidata(h.myfig,h); % Store handles for later
end
function boxchecked(hObject,eventdata)
h = guidata(hObject); % Retrieve handles
% Your code here
end
Set a breakpoint in the boxchecked
function and look at the data given to you by eventdata
(see also the general callback documentation). Three important fields are the Indices
field, which gives you the cell that was edited and caused the callback to execute, and the PreviousData
and NewData
fields, which give you the before and after values of the edited cell.
You'll also want to check to see whether or not the edited cell is a checkbox (CellEditCallback
executes on any change to a cell in a table). Based on this data, decide what action(s) you want to take.