0

After some research, I still can't find the solution for my problem. I have a table that it's filled with info from user, when a button is pushed. The idea is that once new information is inserted and the "add" button pushed, a new row is created on the table. For instance:

  1. Start with a table of 5 rows
  2. The user places the cursor at the third row (selected)
  3. The user clicks on add new row button
  4. A new row is added at row #3 and the old third row is now row #4

Does any of you have a suggestion?

Leonard
  • 2,510
  • 18
  • 37
  • Hi, you may want to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) to make your problem clear and show that you have put effort in asking this question – max Oct 05 '20 at 08:06

1 Answers1

0

Here's one approach. Create a property in your UIFigure called CurrentRow.

properties (Access = private)
    CurrentRow % Last row selected in UITable
end

Whenever the user clicks on a cell in the table, the UITableCellSelection event is fired and you can set the CurrentRow property to be the selected row.

% Cell selection callback: UITable
function UITableCellSelection(app, event)
    app.CurrentRow = event.Indices(1);
end

Next the user clicks the "new row button" and we use the ButtonPushed event to insert the new row.

% 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

Obviously, you will get the new row values from some other control on your form, whereas I've just assigned hard-coded values as an example.

BoilermakerRV
  • 299
  • 1
  • 8