MATLAB Answers

Basic example of cellselectioncallback

조회 수: 9(최근 30일)
Pelajar UM
Pelajar UM 2021년 9월 17일
댓글: Pelajar UM 2021년 9월 18일 7:00
I cannot find any basic example of cellselectioncallback in the documentation. I know that the indices represent rows and columns, but I don't know how to implement it.
I am trying to achieve something like this:
When cell in row 1, column 1 is selected, then
Editfield.Value = 10;
When cell in 2, column 1 is selected, then
Editfield.Value = 22;
etc etc. And you shouldn't be able to select more than 1 cell at a time.

채택된 답변

Adam Danz
Adam Danz 2021년 9월 17일 20:19
편집: Adam Danz 2021년 9월 17일 20:21
The solution to your goal will look something like this where uit is the handle to your uitable.
uit.CellSelectionCallback = @cellSelectionCallbackFcn;
function cellSelectionCallbackFcn(tblHandle, event)
switch event.Indices(1) % row number of selected cell
case 1
val = 10;
case 2
val = 22;
otherwise % optional
val = NaN;
end
Editfield.Value = val;
end
Or, using indexing,
function cellSelectionCallbackFcn(tblHandle, event)
vals = [10, 22];
assert(numel(vals) <= event.Indices(1), '"vals" is undefined for this row.')
Editfield.Value = vals(event.Indices(1));
end
  댓글 수: 1
Pelajar UM
Pelajar UM 2021년 9월 18일 7:00
Perfect. Thank you!

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

추가 답변(0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by