access to checkboxes within Matlab GUI

285 views Asked by At

I have a problem regarding the access to check boxes within Matlab uitable.I have a table in Matlab GUI that has a column of check boxes. I want to open a particular pdf file when a check box is clicked. But I can't find callback of the check boxes within the uitable. Hope the problem is statement is clear.

thanks in advance, Abhirup

1

There are 1 answers

0
sco1 On

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.