필터 지우기
필터 지우기

Is there a way to delete a whole row in a uitable by clicking a delete row button?

조회 수: 31 (최근 30일)
I would like to know if its possible to delete a row in a uitable (genereted in a GUI) by clicking a push button? thanks a lot for the help
p.s. I also would like to know if its possible to make up and down buttons, so the selected row can move up one row or down one row?

답변 (2개)

Walter Roberson
Walter Roberson 2012년 6월 11일
When you create the uitable(), include a column for which ColumnEditable is true, and ColumnFormat is 'logical'. The uitable as a whole should have a CellEditCallback property. When the callback is invoked, the eventdata passed to the callback will be a structure; that structure fill have a field named Indices. When the indices match the row and column of one of your delete check boxes, set() the Data property to be the new cell array with that row deleted.
  댓글 수: 7
Nguyen Thuan
Nguyen Thuan 2020년 8월 4일
편집: Nguyen Thuan 2020년 8월 4일
@ Walter and Image Analyst: Hope that you still remember this post. Currently, I want to delete a row of a UiTable with App Designer in Matlab 2018a. In your code below, what is 'handleToTable' and 'rowToDelete'? Which code I should write in CellEditCallback in order to recognize the row I want to delete?
Could you please provide more detail about this code section?
Thanks in advance!
% Get entire existing table.
tableData = get(handleToTable, 'Data');
% Now delete the row you don't want
tableData(rowToDelete) = []; % or something like that.
% Now send the shorter table back into the uitable.
set(handleToTable, 'Data', tableData);
Walter Roberson
Walter Roberson 2020년 8월 6일
handleToTable is intended to be the handle to the uitable being worked with.
You are wanting to work with App Designer. Using get() with App Designer should still work, but you would be more likely to code
tableData = app.AppropriateHandleName.Data;
rowToDelete is intended to be the index (or indices) of the rows to delete. My original response gave a mechanism for the user to indicate which rows to delete; the discussion after that moved more into the question of how to delete a row in the table when you knew which row "somehow" without having a checkmark for the user to indicate their choice.
With traditional figures you could take advantage of CellSelectCallback to have the user select a cell without a checkbox. However you still need an "activate" / "delete" button to confirm the user's choice... unless you want to delete any cell that the user clicks on (even accidentally.)

댓글을 달려면 로그인하십시오.


Tom
Tom 2012년 7월 3일
편집: Tom 2012년 7월 3일
If you want to delete table data with a pushbutton, then I think you'll have to also have a cell selection callback so you know what cell was last selected.
set(UITABLEHANDLE,'CellSelectionCallBack',@(h,e) set(h,'UserData',e))
Will make the indices of the last cell selected available in the user data of the table. Then, you can use that info for a pushbutton:
D=get(UITABLEHANDLE,'Data');
Index=get(UITABLEHANDLE,'UserData');
D(Index(1))=[];
set(UITABLEHANDLE,'Data',D);
There may well be a better way of doing it than this, but it's a start
  댓글 수: 6
Nguyen Thuan
Nguyen Thuan 2020년 8월 11일
Updated: Following Tom's code, I succeeded to delete rows when selecting an arbitrary cell in the Table. I put the whole code inside Callback function of Delete Button.
But problem is that sometime when I click the Delete Button, there is an error:" Dot indexing is not supported for variables of this type." When I repeated do it for several times, the problem disappeared.
Is there anyone knowing the root of that error? Or is it a bug of Matlab 2018a, a version which I am using?
Cristian Martin
Cristian Martin 2022년 5월 23일
I applied my self the code and it's ok, it delete the row selected but when I want to add new row with other values it bring back also the deleted rows...
Do you know why?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by