필터 지우기
필터 지우기

Row Editable in Table...?

조회 수: 17 (최근 30일)
suraj mate
suraj mate 2024년 2월 27일
편집: Voss 2024년 2월 28일
I have one table in matlab in that table i want first row editable for all columns and all other Rows should not editable across all columns .
is if possible if yes how can i do it...?
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2024년 2월 28일
I asked the same to the MATLAB Central AI Chat Playground and it said the following -
To make the first row editable and all other rows non-editable in a MATLAB table, you can use the uitable function along with the CellEditCallback property. Here's an example:
% Create a sample table
data = {'John', 25, 'USA'; 'Emily', 30, 'UK'; 'Michael', 35, 'Australia'};
columnNames = {'Name', 'Age', 'Country'};
table = uitable('Data', data, 'ColumnName', columnNames);
% Set the CellEditCallback property
set(table, 'CellEditCallback', @(src, event) editCallback(src, event));
% Callback function to handle cell editing
function editCallback(src, event)
% Get the row and column indices of the edited cell
row = event.Indices(1);
col = event.Indices(2);
% Allow editing only for the first row
if row == 1
% Allow editing
src.Data{row, col} = event.NewData;
else
% Revert to the previous value
src.Data{row, col} = event.PreviousData;
end
end
Voss
Voss 2024년 2월 28일
편집: Voss 2024년 2월 28일
That seems like a potentially viable workaround.
Of course, since the default for uitable is that no columns are editable, you'd have to change that for the CellEditCallback to have any effect, e.g.:
% Set the ColumnEditable and CellEditCallback properties
set(table, ...
'ColumnEditable', true, ...
'CellEditCallback', @(src, event) editCallback(src, event));

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by