uitable's cells as a readonly
이전 댓글 표시
Hi,
I would like to know how I can set several cells of a uitable like a readonly effect.
Thanks
regards.
댓글 수: 2
Sarah Wait Zaranek
2011년 3월 1일
Would you like them to be not editable? Did you already try the "ColumnEditable" property?
Mtlb Usr
2011년 3월 2일
채택된 답변
추가 답변 (1개)
Oleg Komarov
2011년 3월 1일
Here an example that allows you to set as non editable just some cells of a column:
function exampleGUI
f = figure('Position',[200 200 400 150]);
dat = rand(3);
cnames = {'X-Data','Y-Data','Z-Data'};
rnames = {'First','Second','Third'};
t = uitable('Parent',f,'Data',dat,'ColumnName',cnames,...
'RowName',rnames,'Position',[20 20 360 100],...
'ColumnEditable',[true true true],'CellEditCallback',@t_ced);
function t_ced(varargin)
% Retrieve info on edited cell
edC = varargin{2};
% Transform subscipts of selected cell into idx
idx = sub2ind(size(dat),edC.Indices(1),edC.Indices(2));
% If idx falls into 5-9 range set back previous value
if ismember(idx, 5:9)
data = get(t,'data');
data(idx) = edC.PreviousData;
set(t,'data',data)
end
end
end
Save it as exampleGUI and run it. Only cells 5-9 are non editable.
댓글 수: 3
Mtlb Usr
2011년 3월 2일
Oleg Komarov
2011년 3월 2일
Change ColumnEditable to Editable if that's the case for your version.
Mtlb Usr
2011년 3월 3일
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!