uifigure+uitree, multiple selected nodes

22 次查看(过去 30 天)
Martin
Martin 2025-8-19,11:03
评论: Martin 2025-8-20,7:52
Hello,
Does anybody know a (undocumented) workaround to have multiple nodes selected in a uitree with checkboxes? I like to distinguish between checked and selected items.
If the uitree component is used without checkboxes it is possible. I am wondering why this is not implemented (yet)...
hF = uifigure();
hT = uitree(hF,'checkbox');
hO1 = uitreenode(Parent=hT, Text='object1');
hO2 = uitreenode(Parent=hT, Text='object2');
hO3 = uitreenode(Parent=hT, Text='object3');
hO4 = uitreenode(Parent=hT, Text='object4');
hT.CheckedNodes = [hO1, hO2];
hT.SelectedNodes = [hO3, hO4];
%Error using matlab.ui.container.internal.model.TreeComponent/set.SelectedNodes (line 161)
%'SelectedNodes' must be an empty array or a 1-by-1 TreeNode object that is a child in the CheckBoxTree.
Thanks in advance,
Martin

采纳的回答

dpb
dpb 2025-8-19,14:11
编辑:dpb 2025-8-19,15:37
Does not appear to be possible; looking at the undocumented/hidden properties with <Yair Altman getundoc> reveals that the 'MultiSelect' property doesn't even exist, rather than simply not made public. Given this, it would not appear possible to modify the current behavior using the 'Style','Checkbox' option.
One could use independent check boxes and manipulate them with a callback to set their state(s) based on the properties of a standard tree with 'MultiSelect','on'. I dunno about how much effort it would be to also draw in a background to match, though.
Another option could be to use an uitable with a checkbox column.
  2 个评论
dpb
dpb 2025-8-19,14:51
Submit this to Mathworks as an official support request for enhancement at <Product Support Page>; mayhaps an official response as to there being some reason the option isn't available with the checkbox style that isn't apparent superficially.
Martin
Martin 2025-8-20,7:52
@dpb thanks for your time to react. I will take your alternative suggestions in mind and will send a service request (feature request) to Mathworks.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by