How to deselect a cell on uitable using CellSelectionCallback?
Show older comments
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 Comments
Adam Danz
on 30 Jul 2018
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
on 9 Aug 2018
Adam Danz
on 9 Aug 2018
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
on 21 Aug 2018
telmo egues
on 21 Aug 2018
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
on 21 Aug 2018
Adam Danz
on 21 Aug 2018
Nice. I posted the rest as an answer so that this question is marked as solved.
Matlab Pro
on 27 Dec 2023
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;
Accepted Answer
More Answers (1)
Jonghoon Kim
on 7 Jan 2022
0 votes
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
Categories
Find more on App Building in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!