Removing uitable cell selection highlight

28 ビュー (過去 30 日間)
Jim
Jim 2013 年 5 月 14 日
回答済み: Jonghoon Kim 2022 年 1 月 7 日
Hi,
I have a uitable that includes a checkboxes in column 1 and string-valued entries in column 2. Some of the entries may be "ghosted", which is faked by prepending HTML tags to change their font color to gray. A corresponding bitvector keeps track of the ghosted rows. Clicking in either column on a ghosted row is ignored, with an immediate return from the CellSelectionCallback routine.
This works OK except for one annoyance: When a ghosted string (column 2 of a ghosted row) is clicked, the blue cell selection highlight remains on after the return from the callback. A subsequent click in column 1 of the same row, will remove it, but that's not a good solution. Can anyone suggest a way to programmatically remove it ("deselect" the clicked cell)?
BTW, I just purchased Yair Altman's excellent book Undocumented Secrets of MATLAB-Java Programming, but this doesn't seem to be a covered topic.

採用された回答

Yair Altman
Yair Altman 2013 年 5 月 18 日
This is covered (briefly) at the bottom of page 169 of my book...
  3 件のコメント
telmo egues
telmo egues 2018 年 7 月 30 日
Hi, I've tried this solution and didn't work, how would you write the code of this?
Thanks in advance
Jim
Jim 2018 年 7 月 30 日
This works for me. It's inside the uitable's CellSelectionCallback:
if any(ghostRows == clickedRow)
myTable = src.Data;
temp = myTable;
temp(end) = {'DUMMY'};
src.Data = temp;
src.Data = myTable;
return
end
If I click on a ghosted row in the string-valued column, the focus highlight (dotted box around entry) still appears, but I find that much less objectionable than turning the entire cell background blue as happened before.

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2013 年 5 月 14 日
You could try setting the uitable to 'enable' 'off', drawnow(), then 'enable' 'on' and drawnow()
  2 件のコメント
Jim
Jim 2013 年 5 月 15 日
Walter, Thanks for the suggestion, but unfortunately that doesn't work. I've also tried a plain drawnow() without toggling the enable property, and a figure() call. No joy so far. -Jim
Jim Hokanson
Jim Hokanson 2021 年 11 月 1 日
This accomplishes what I want, which is unlinking the keyboard from the cell. Now the up and down arrows don't navigate cells, which for my particular program was causing other problems. Note, you still have a visual indication of the cell being selected (gray box instead of blue), which in my case is OK. Ideally TMW would just provide a method to implement the actual desired feature! :/

サインインしてコメントする。


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 Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by