Clear Filters
Clear Filters

How to disable uitreenode?

23 views (last 30 days)
Elando
Elando on 14 Mar 2017
Answered: Lior de Marcas on 18 Nov 2021
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

Answers (1)

Lior de Marcas
Lior de Marcas on 18 Nov 2021
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"

Categories

Find more on Develop uifigure-Based Apps 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!