How to deselect a cell on uitable using CellSelectionCallback?

조회 수: 26 (최근 30일)
telmo egues
telmo egues 2018년 7월 30일
댓글: Noah 2023년 12월 27일
Hi, Tried several solutions found in the forum but none of them worked, in my program, when a cell is selected, all the info of the row is displayed in different edit cases, when the cell in the uitable is edited and enter is pressed, the wanted value changes properly but the CellSelectionCallback is called again and the indices this time are inexistent and returns an error. Any way of fixing this? Thanks in advance
  댓글 수: 10
Adam Danz
Adam Danz 2018년 8월 21일
Nice. I posted the rest as an answer so that this question is marked as solved.
Noah
Noah 2023년 12월 27일
Hi - this simples way to do is just to "refresh" the "Data" field;
% Refresh the "Data" field" to its own = Unselect
handles.my_tbl.Data = handles.my_tbl.Data;

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

채택된 답변

Adam Danz
Adam Danz 2018년 8월 21일
편집: Adam Danz 2018년 8월 21일
Following the comments under the question, we've arrived to the answer.
For some reason, pressing enter after entering data in a UItable activates your cellselectionCallback (which isn't the case when I try it using a simple UI table in 2018a).
When your cellSelectionCallback is activated after pressing enter, the indices are empty.
The real solution would be to prevent the unnecessary callback in the first place but without playing around with your entire GUI I cannot do that remotely.
The alternative solution is to escape from the callback function when the indices are empty.
Insert this at the top of your cellSelectionCallback function.
if isempty(eventdata.Indices)
return
end

추가 답변 (1개)

Jonghoon Kim
Jonghoon Kim 2022년 1월 7일
function [] = DeselectCellinUItable()
%---------------------------------------------------------------
uif = uifigure();
uif.Units = 'normalized';
uif.Position = [0.10, 0.50, 0.80, 0.40];
%---------------------------------------------------------------
uit = uitable(uif);
uit.Units = 'normalized';
uit.Position = [0.10, 0.50, 0.80, 0.40];
uit.Data = cell2table(num2cell(rand(10,7)));
uit.RowName = 'numbered';
uit.ColumnEditable = true;
uit.SelectionType = 'cell';
uit.Multiselect = 'off';
uit.SelectionChangedFcn = @(src,event) DeselectUItable;
%---------------------------------------------------------------
function DeselectUItable
uit.Selection = [];
end
%---------------------------------------------------------------
end

카테고리

Help CenterFile Exchange에서 Functions에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by