- 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.
How to select child nodes from parent nodes in Uitree
조회 수: 20 (최근 30일)
이전 댓글 표시
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
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:
참고 항목
카테고리
Help Center 및 File Exchange에서 Install Products에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!