How to disable uitreenode?

14 Ansichten (letzte 30 Tage)
Elando
Elando am 14 Mär. 2017
Beantwortet: Lior de Marcas am 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

Antworten (1)

Lior de Marcas
Lior de Marcas am 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"

Kategorien

Mehr zu Develop uifigure-Based Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by