【问题标题】:Add a new row between old table rows in Matlab appdesigner在 Matlab appdesigner 中的旧表行之间添加新行
【发布时间】:2021-01-18 19:21:02
【问题描述】:
经过一番研究,我仍然找不到解决问题的方法。当按下按钮时,我有一个表格,其中包含来自用户的信息。这个想法是,一旦插入新信息并按下“添加”按钮,就会在表上创建一个新行。例如:
- 从 5 行的表格开始
- 用户将光标放在第三行(选中)
- 用户点击添加新行按钮
- 在第 3 行添加了一个新行,旧的第三行现在是第 4 行
大家有什么建议吗?
【问题讨论】:
标签:
matlab
matlab-app-designer
【解决方案1】:
这是一种方法。在您的 UIFigure 中创建一个名为 CurrentRow 的属性。
properties (Access = private)
CurrentRow % Last row selected in UITable
end
每当用户单击表格中的单元格时,都会触发UITableCellSelection 事件,您可以将CurrentRow 属性设置为选定行。
% Cell selection callback: UITable
function UITableCellSelection(app, event)
app.CurrentRow = event.Indices(1);
end
接下来用户点击“新行按钮”,我们使用ButtonPushed事件插入新行。
% Button pushed function: Button
function ButtonPushed(app, event)
insertedRow = [1 2 3 4];
temp = [app.UITable.Data(1:app.CurrentRow-1,:);insertedRow;app.UITable.Data(app.CurrentRow:end,:)];
app.UITable.Data = temp;
end
显然,您将从表单上的其他控件获取新的行值,而我刚刚分配了硬编码值作为示例。