我在访问 Matlab uitable 中的复选框时遇到问题。我在 Matlab GUI 中有一个表,其中有一列复选框。单击复选框时,我想打开特定的 pdf 文件。但我在 uitable 中找不到复选框的回调。希望问题是陈述清楚。
提前致谢, 阿比鲁普
我在访问 Matlab uitable 中的复选框时遇到问题。我在 Matlab GUI 中有一个表,其中有一列复选框。单击复选框时,我想打开特定的 pdf 文件。但我在 uitable 中找不到复选框的回调。希望问题是陈述清楚。
提前致谢, 阿比鲁普
CellEditcallback
为您的桌子创建自己的。
举个例子:
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
在函数中设置断点boxchecked
并查看提供给您的数据eventdata
(另请参阅通用回调文档)。三个重要的字段是Indices
字段,它为您提供已编辑并导致回调执行的单元格,以及PreviousData
和NewData
字段,它为您提供已编辑单元格的前后值。
您还需要检查编辑的单元格是否是复选框(CellEditCallback
对表格中的单元格进行任何更改时执行)。根据这些数据,决定您要采取的行动。