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!