Appdesigner - Edit the column names during run time
Show older comments
Hello everybody, I am trying to create an app in MATLAB appdesigner. While trying to insert a table with the number of rows and columns as input from the user and initialized using a push button, I am not able to vary the names of the column headers.
If I take 'numbered' option it is adjusting to the input but I am not able to edit the column names.
Please let me know if there is any option for this.
Thank you
6 Comments
Cris LaPierre
on 18 Aug 2021
Can you share the code you are using to create the table?
shyam prithvi tanuku
on 18 Aug 2021
Edited: Cris LaPierre
on 18 Aug 2021
Cris LaPierre
on 18 Aug 2021
Your edit field callbacks are unnecessary given the code you have shared. The code is duplicated in your pushbutton callback. If you do want to use edit field callbacks to set variable values, you should make the variables app properties. See here: https://www.mathworks.com/help/matlab/creating_guis/share-data-across-callbacks-in-app-designer.html
It looks like you have already added 4 table components to your app canvas (named app.producers, app.consumers, app.connections and distribution). Is that correct?
I do not understand where the 'create connections' code at the bottom is coming from. Is it necessary if you have already added a app.connections Table component to your canvas? I assume you must because you are setting its properties in the push button callback.
shyam prithvi tanuku
on 19 Aug 2021
Cris LaPierre
on 19 Aug 2021
It is possible. If it is meant to be part of the pushbutton callback, it needs to be placed before the end statement.
What still isn't clear, though, is where you are going to place it because the first line (app.connections = uitable(app.UIFigure);) overwrites app.connections, removing any information you previously added to it.
This at least works for me, assuming N0G+NoPM = 4
function InitializeButtonPushed(app, event)
%% Produers table
NoG = app.NumberofGenSetsEditField.Value;
NoPM = app.NumberofPrimemoversEditField.Value;
NoR = NoG+NoPM;
app.producers.Data= cell(NoR,3);
app.producers.ColumnEditable = true;
%%consumers table
NoC = app.NumberofConsumersEditField.Value;
app.consumers.Data= cell(NoC,2);
app.consumers.ColumnEditable = true;
% Create connections
app.connections = uitable(app.UIFigure);
app.connections.ColumnName = {'source'; 'GS1'; 'GS2'; 'PM2'; 'PM2'};
app.connections.RowName = {};
app.connections.ColumnEditable = true;
app.connections.CellEditCallback = createCallbackFcn(app, @connectionsCellEdit, true);
app.connections.Position = [15 220 624 185];
%connections table
NoS = app.NumberofSwitchboardsEditField.Value;
app.connections.Data= cell(NoS+1,NoR+1);
%%distribution table
NoP = app.NumberofPropulsorsEditField.Value;
app.distribution.Data= cell(NoC+NoP,NoS+1);
app.distribution.ColumnEditable = true;
end
shyam prithvi tanuku
on 20 Aug 2021
Accepted Answer
More Answers (0)
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!