【问题标题】:Add a new row between old table rows in Matlab appdesigner在 Matlab appdesigner 中的旧表行之间添加新行
【发布时间】:2021-01-18 19:21:02
【问题描述】:

经过一番研究,我仍然找不到解决问题的方法。当按下按钮时,我有一个表格,其中包含来自用户的信息。这个想法是,一旦插入新信息并按下“添加”按钮,就会在表上创建一个新行。例如:

  1. 从 5 行的表格开始
  2. 用户将光标放在第三行(选中)
  3. 用户点击添加新行按钮
  4. 在第 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

显然,您将从表单上的其他控件获取新的行值,而我刚刚分配了硬编码值作为示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-10
    • 2020-06-10
    • 1970-01-01
    • 2016-05-05
    • 2023-03-03
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多