1. uitable 不能输入字符么? 为什么GUI运行后,输入字符,当单元格失去焦点时,单元格自动变为NaN了呢?
2. 在uitable的某个单元格 输入数字后,又删除了这些数字,单元格会显示NaN而不是空白的,为什么会这样呢?能不能重新显示空白的呢?
谢谢
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
自己的问题还是自己解决……
我的方法是:(虽然很笨)
1. 在CellEditCallback函数里添加:
function table_CellEditCallback(hObject, eventdata, handles)
% hObject handle to table (see GCBO)
% eventdata structure with the following fields (see UITABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
r=eventdata.Indices;
dd = get(hObject,'Data');
dd(r(1),r(2)) = {eventdata.EditData};
2. 对于只能输入数字的一些,我是这样做的
function table_CellEditCallback(hObject, eventdata, handles)
% hObject handle to table (see GCBO)
% eventdata structure with the following fields (see UITABLE)
% Indices: row and column indices of the cell(s) edited
% PreviousData: previous data for the cell(s) edited
% EditData: string(s) entered by the user
% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
% Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
b=str2num(eventdata.EditData);
r=eventdata.Indices;
if ~(isnumeric(b)&&isempty(b)==0)
% 如果不是数字,清空单元格
dd = get(hObject,'Data');
dd(r(1),r(2)) = cell(1);
set(hObject,'Data',dd)
end
这样虽然解决了输入-显示的问题 可是我们会发现 数据全都显示在cell的左侧 和默认输入时显示在右侧的不一样
不知道有没有牛人能用简单的方法解决这个问题呢?
谢谢
[本帖最后由 edifiers2008 于 2009-2-20 19:21 编辑]