How to select child nodes from parent nodes in Uitree

14 vues (au cours des 30 derniers jours)
ZC Song
ZC Song le 28 Avr 2019
Modifié(e) : Inso le 17 Oct 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 commentaires
Guillaume
Guillaume le 28 Avr 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 le 28 Avr 2019
Modifié(e) : ZC Song le 28 Avr 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?

Connectez-vous pour commenter.

Réponses (1)

Inso
Inso le 17 Oct 2019
Modifié(e) : Inso le 17 Oct 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'.

Catégories

En savoir plus sur Install Products dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by