How to select child nodes from parent nodes in Uitree

조회 수: 13 (최근 30일)
ZC Song
ZC Song 2019년 4월 28일
편집: Inso 2019년 10월 17일
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
Guillaume
Guillaume 2019년 4월 28일
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 2019년 4월 28일
편집: ZC Song 2019년 4월 28일
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?

댓글을 달려면 로그인하십시오.

답변 (1개)

Inso
Inso 2019년 10월 17일
편집: Inso 2019년 10월 17일
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'.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by