Right click to remove row(s) from uitable - example code is not working
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bowei Li
am 11 Okt. 2023
Beantwortet: Walter Roberson
am 11 Okt. 2023
Hi! I'm trying to use context menu to enable row removing from uitable by following an example here:
function tableApp
fig = uifigure;
tbl = uitable(fig);
tbl.Position = [20 20 400 300];
tbl.Data = randi(10,[10 4]);
cm = uicontextmenu(fig);
m = uimenu(cm);
m.Text = "Delete Row";
tbl.ContextMenu = cm;
m.MenuSelectedFcn = @deleteRow;
cm.ContextMenuOpeningFcn = @(src,event)toggleVisibility(src,event,m);
end
function deleteRow(src,event)
tbl = event.ContextObject;
row = event.InteractionInformation.Row;
tbl.Data(row,:) = [];
end
function toggleVisibility(src,event,m)
row = event.InteractionInformation.Row;
rowClicked = ~isempty(row);
m.Visible = rowClicked;
end
However, I run into this problem:
>> tableApp
Unrecognized method, property, or field 'InteractionInformation' for class 'matlab.ui.eventdata.ActionData'.
Error in tableApp>toggleVisibility (line 23)
row = event.InteractionInformation.Row;
Error in tableApp>@(src,event)toggleVisibility(src,event,m) (line 13)
cm.ContextMenuOpeningFcn = @(src,event)toggleVisibility(src,event,m);
Error using matlab.ui.internal.WebContextMenuController/handleEvent
Error while evaluating ContextMenu Callback.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 11 Okt. 2023
Which release are you using? Some of that is only applicable to R2023b and later; https://www.mathworks.com/help/matlab/ref/uicontextmenu.html?searchHighlight=uicontextmenu&s_tid=srchtitle_support_results_1_uicontextmenu#mw_c3c8080d-01ad-48ab-9c13-416405690017
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!