Deleting rows from a uitable

조회 수: 3 (최근 30일)
PN
PN 2011년 1월 21일
My question appears to be rather simple, but I haven't been able to come across a solution yet. Suppose we have a pushbutton that will be used to delete a given row within said uitable. I need to get the information as to which row is selected before I delete it.
.
So, first of all, how do I select an entire row in the uitable (i seem to be restricted to selecting cells), and secondly, what type of callback (CellSelectionCallBack perhaps) should I be looking to get.
.
Finally, how do I get the information from this callback, i.e. is it possible to store the row number in a variable?

채택된 답변

Doug Hull
Doug Hull 2011년 1월 21일
You can not select a column or a row currently (2010b). You can select cells. You might be able to hack something together from that selection. Is that something you are willing to do? If so, edit your question to reflect this.

추가 답변 (2개)

Sam G.
Sam G. 2011년 1월 21일
You could use the UserData property to store the row and column of the selected cell, then access it whenever you need it with
ud = get(handles.uitable1, 'UserData')
ud(1,1) would be the row index and ud(1,2) would be the column index. In the CellSelectionCallback you would need something like this
set(handles.uitable1, 'UserData', eventdata.Indices)
to store the row and column indices of the currently selected cell in the uitable's UserData. There are some complexities to work out like what to do when the user selects multiple cells, but that's the basic idea.

PN
PN 2011년 1월 24일
Ok I now understand that I can't select an entire row. Let us suppose then that I want to select a given cell, and from that obtain the row index.
I have used the suggestion above:
function csplate_table_CellSelectionCallback(hObject, eventdata, handles)
set(handles.hObject,'UserData', eventdata.Indices)
However, this seems to be doing nothing at all, because everytime I click a cell I don't seem to be able to trigger the 'set' event.
Thanks for the attention shared so far.
  댓글 수: 1
PN
PN 2011년 1월 24일
I realized I can't use the hObject reference. It seems to be working now.
Thank you for the previous answers!

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by