Add User Text Input to Next Line in Table via Button Push in App Designer

1 view (last 30 days)
I am building an app in AppDesigner that allows the user to enter reagent information and add it a running list in a table after clicking the "Add Reagent" button. Clicking the button also clears the text fields. I have code that allows adding one row to the table, but I am struggling with how to allow the user to add multiple rows to the table with the same button. I wasn't able to add multiple button pushed callbacks to the button.
The code below details the callbacks for the edit text fields and the "Add Reagent" button.
% Value changed function: ReagentIDEditField
function ReagentIDEditFieldValueChanged(app, event)
global A1;
A1 = app.ReagentIDEditField.Value;
end
% Value changed function: BlockersEditField
function BlockersEditFieldValueChanged(app, event)
global D1;
D1 = app.BlockersEditField.Value;
end
% Value changed function: AssayNameEditField
function AssayNameEditFieldValueChanged(app, event)
global C1;
C1 = app.AssayNameEditField.Value;
end
% Value changed function: ConditionEditField_2
function ConditionEditField_2ValueChanged(app, event)
global B1;
B1 = app.ConditionEditField_2.Value;
end
% Value changed function: WashEditField
function WashEditFieldValueChanged(app, event)
global E1;
E1 = app.WashEditField.Value;
end
% Button pushed function: AddReagentButton
function AddReagentButtonPushed(app, event)
global A1;
global B1;
global C1;
global D1;
global E1;
reagentID = cell([5,1]);
conditionNum = cell([5,1]);
assayNam = cell([5,1]);
blockVals = cell([5,1]);
washVals = cell([5,1]);
t = table(reagentID, conditionNum, assayNam, blockVals, washVals);
app.ReagentTable.Data = t;
app.ReagentTable.Data{1,1}{1} = A1;
app.ReagentTable.Data{1,2}{1} = B1;
app.ReagentTable.Data{1,3}{1} = C1;
app.ReagentTable.Data{1,4}{1} = D1;
app.ReagentTable.Data{1,5}{1} = E1;
ClearFields(app)
end
end

Accepted Answer

Kevin Holly
Kevin Holly on 5 Aug 2022
Please see the app attached and the code below:
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.ReagentTable.Data = [];
end
% Button pushed function: AddReagentButton
function AddReagentButtonPushed(app, event)
app.ReagentTable.Data = [app.ReagentTable.Data;{app.ReagentIDEditField.Value,app.ConditionEditField.Value,app.AssayNameEditField.Value,app.BlockersEditField.Value,app.WashEditField.Value}];
end
end
FYI, You do not need to use global vairables. I have simplified the code you wrote earlier below. For the solution, please see the code above and the app attached.
% Value changed function: ReagentIDEditField
function ReagentIDEditFieldValueChanged(app, event)
% Button pushed function: AddReagentButton
function AddReagentButtonPushed(app, event)
reagentID = cell([5,1]);
conditionNum = cell([5,1]);
assayNam = cell([5,1]);
blockVals = cell([5,1]);
washVals = cell([5,1]);
t = table(reagentID, conditionNum, assayNam, blockVals, washVals);
app.ReagentTable.Data = t;
app.ReagentTable.Data{1,1}{1} = app.ReagentIDEditField.Value;
app.ReagentTable.Data{1,2}{1} = app.ConditionEditField_2.Value;
app.ReagentTable.Data{1,3}{1} = app.AssayNameEditField.Value;
app.ReagentTable.Data{1,4}{1} = app.BlockersEditField.Value;
app.ReagentTable.Data{1,5}{1} = app.WashEditField.Value;
ClearFields(app)
end
end

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!