How to select child nodes from parent nodes in Uitree

14 visualizzazioni (ultimi 30 giorni)
ZC Song
ZC Song il 28 Apr 2019
Modificato: Inso il 17 Ott 2019
Hi,
I want to ask how to select mutiple nodes in Tree structure, below is my interface:
There are three main nodes and each has two subnodes. My purpose is that when I choose any main node, the two panels in the right side is unactivated (as shown in figure). The problem is when I choose one of subnodes, I want the correspond panel to be activated. For example, when I choose 'Vertical loading' with "time history", the Time history loading will be activated.
Here is my code:
function TreeSelectionChanged(app, event)
selectedNode = app.Tree.SelectedNodes;
% Enable form only when a child is selected
% Items = {'Hydraulogic loading','Vertical loading','Horizontal loading'};
subItems = {'Constant','Time history'};
switch selectedNode.Text
case "Hydraulogic loading"
disableForm1(app);
disableForm2(app);
if strcmp(selectedNode.Text,'Constant')
enableForm1(app);
disableForm2(app);
elseif strcmp(selectedNode.Text,subItems(2))
enableForm2(app);
disableForm1(app);
end
case "Vertical loading"
disableForm1(app);
disableForm2(app);
if strcmp(selectedNode.Text,subItems(1))
enableForm1(app);
disableForm2(app);
elseif strcmp(selectedNode.Text,subItems(2))
enableForm2(app);
disableForm1(app);
end
case "Horizontal loading"
disableForm1(app);
disableForm2(app);
if strcmp(selectedNode.Text,subItems(1))
enableForm1(app);
disableForm2(app);
elseif strcmp(selectedNode.Text,subItems(2))
enableForm2(app);
disableForm1(app);
end
end
Thank you very much!
  2 Commenti
Guillaume
Guillaume il 28 Apr 2019
It's not clear from your question what exactly is the problem. There are several things not quite right with the code you've shown:
  • You turn multiselect on in a change event of the tree. That's very odd. Usually, that property is set just once, when the tree is created.
  • You have mispelled items, and it's not clear why they are hardcoded in the event function instead of being retrieved from the tree.
  • You say that you want to allow multiselect, in which case the SelectedNodes property of the tree will return an array (there's a reason the property ends with an 's', 's' that you've misleadingly omitted from your own variable). An array is not allowed in a switch expression, so in case of a multiselect, your code will throw an error
  • Using switch statement like these are usually a bad idea. What if you want to handle 20 different cases? Will you write 20 different case statements?
  • There is no difference between any of the case, so it's not even clear what their purpose is.
ZC Song
ZC Song il 28 Apr 2019
Modificato: ZC Song il 28 Apr 2019
Thanks for your reply.
First I want to sorry about my poor description about the problem.
Yes, the "multiselect" is set on when the tree is created, I put here just to tell I turn it on. As you mentioned, I will take it off.
Actually, the purpose is simple: when I click each main node, the panel in the right side remains inactivated. Instead, when I click each subnode within the main node, the corresponding edit field of the corrsponding panel will active while the other is not. For example, when I choose the "constant" under the "Hydraulogic loading", the "Rainfall intensity" will delighted as below:
Could you please give me some hint for such that purpose?

Accedi per commentare.

Risposte (1)

Inso
Inso il 17 Ott 2019
Modificato: Inso il 17 Ott 2019
You can simply disable the two panels as default. Then enable them based on the jugdement of SelectedNode.Text. I don't understand why you need 'multiselect'.

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by