フィルターのクリア

How to add a column to a UItable in AppDesigner

34 ビュー (過去 30 日間)
Mark Eigenraam
Mark Eigenraam 2022 年 1 月 20 日
コメント済み: Simon Chan 2022 年 1 月 20 日
I have created a UITable. I have a button which I want the user to be able to add a column and assign there own name to it.
I can rename a column: app.UITable.ColumnName{1} = 'mark';
I can add a name: app.UITable.ColumnName{end+1} = 'mark';
but when I add it does not display, why not?

回答 (1 件)

Simon Chan
Simon Chan 2022 年 1 月 20 日
I think it is better to record the number of columns in the uitable before you added a new column and assign the name to the new column as follows:
Nc = length(app.UITable.ColumnName); % Record the original number of columns in uitable
%
% Your code adding new column in the uitable
%
app.UITable.ColumnName{Nc+1} = 'New Column'
  4 件のコメント
Mark Eigenraam
Mark Eigenraam 2022 年 1 月 20 日
% Button pushed function: AddcolumnButton
function AddcolumnButtonPushed(app, event)
new_name = inputdlg('Please enter new column name');
if isempty(new_name)
%user has pressed cancel or not entered any text
return
end
app.UITable.Data(:,end+1)={''}; % add column
% column_name=char(inputdlg('Please enter new column name'));
app.UITable.ColumnName{end+1}=char(new_name);
%app.UITable.ColumnSortable(end+1) = 1;
%app.UITable.ColumnSortable = [true false true true];
%app.UITable.ColumnEditable = [true false true true];
end
this is now adding a column and a name, but the table data (app.UITable.Data) do not include the name at the top
Simon Chan
Simon Chan 2022 年 1 月 20 日
I am a little bit confuse now.
If you want the data inside the table to display the ColumnName as well, add one more line as follows:
app.UITable.Data(:,end+1)={''}; % add column
app.UITable.Data(:,end)=new_name; % Put the name inside the new column

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by