How to deselect a cell on uitable using CellSelectionCallback?
이전 댓글 표시
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
2018년 7월 30일
When I select a cell in a uitable the CellSelectionCallback is executed but when I enter a value in that cell and press enter, the CellSelectionCallback is not called again. Do you have a CellEditCallback function or some other function that might be calling your CellSelectionCallback?
telmo egues
2018년 8월 9일
Adam Danz
2018년 8월 9일
If you attach the code for the GUI and explain which callback functions interact with the table I might be able to poke around later.
telmo egues
2018년 8월 21일
telmo egues
2018년 8월 21일
We're getting closer. Could you look into these two possibilities:
1) when you select the cell, everything works ok but when you press enter, the value of indices is empty. To test that, print out the value of 'indices' to the command window and select a cell, then press enter.
2) If possibility 1 is ruled out, check if the indices are correct after pressing enter but the value of 'matriz' has changed. If your cell selection is not changing then 'indices' should be the same values after pressing enter. The array bounds error could be due to the size of matriz changing. Perhaps print out matriz if it's not too big and see if it's changed between selecting the cell and pressing enter.
Lastly, let's make clear what your final goal is. In the title of your question, you ask to deselect a cell. But is your real goal just solving this problem?
telmo egues
2018년 8월 21일
Adam Danz
2018년 8월 21일
Nice. I posted the rest as an answer so that this question is marked as solved.
Matlab Pro
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;
채택된 답변
추가 답변 (1개)
Jonghoon Kim
2022년 1월 7일
0 개 추천
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
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!