How to disable uitreenode?

19 次查看(过去 30 天)
Elando
Elando 2017-3-14
I made a uitree in a GUI and I'd like to disable this tree because I want it only to show the structure and not to surf through it.
Is it possible to disable the uitreenode and make them not selectable? When the user press on a node I don't want to make it selected.
Thank you

回答(1 个)

Lior de Marcas
Lior de Marcas 2021-11-18
I guess the easiest way is to define it in the SelectionChangedFcn of the uitree:
fig = uifigure;
t = uitree(fig);
parent = uitreenode(t,'Text',"parent");
child = uitreenode(parent,'Text',"child");
expand(t)
t.SelectionChangedFcn = @(treeobj,~) ParentUnselectible(treeobj)
function ParentUnselectible(treeobj)
if strcmp(treeobj.SelectedNodes.Text,"parent")
treeobj.SelectedNodes = [];
end
end
Multiselect "on" will require few additional changes. If you base it the node property "Text" (as I did) each node will have to have unique name & editable will break it - it better done using the "Tag" property, or by hard-coding handle list & using "ismember"

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by