- 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
13 次查看(过去 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!