How to delete a row in a editable table in an app?

10 ビュー (過去 30 日間)
Giulia Di Giorgio
Giulia Di Giorgio 2023 年 3 月 5 日
編集済み: Mario Malic 2023 年 3 月 7 日
Hello, I already programed an "add row" button but I don't know how to program a "delete row " button.I tried to copy the same function and add a - instead of a + but it does not work. I'll attach the captures with the code, including the FCN start up callback. Thank you

採用された回答

Mario Malic
Mario Malic 2023 年 3 月 5 日
編集済み: Mario Malic 2023 年 3 月 7 日
Hey,
idx = app.UITable.Selection(1);
app.UITable.Data(idx, :) = [];
Selection varies whether you have MultiSelect on or off. Check this document if you have MultiSelect on https://www.mathworks.com/help/matlab/ref/matlab.ui.control.table-properties.html#d124e1617327
Below is Walter's comment from the comment section.
%inside callback
fila = app.UITable.Selection;
if isempty(app.UITable.Data) || isempty(fila); return; end %table is empty or nothing is selected
app.UITable.Data(fila(1),:) = []; %delete what is selected
  10 件のコメント
Walter Roberson
Walter Roberson 2023 年 3 月 6 日
%inside callback
fila = app.UITable.Selection;
if isempty(app.UITable.Data) || isempty(fila); return; end %table is empty or nothing is selected
app.UITable.Data(fila(1),:) = []; %delete what is selected
Giulia Di Giorgio
Giulia Di Giorgio 2023 年 3 月 6 日
Thank you Walter it works perfectly :)!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by