buddingdeveloper-3601 avatar image
0 Votes"
buddingdeveloper-3601 asked FayWang-MSFT commented

How to select all the child nodes without selecting the parent node of a treeview in 1803 version

I am using a treeview control in my uwp project which supports 1803 version. I will add the nodes to selected nodes programmatically when it is clicked. Consider a parent node with a single child node. When the child node is clicked, I will add it to the selected nodes programmatically but the parent node also added to selected nodes automatically. I don't want the parent node to be added to the selected nodes. Is there any way we can restrict it? It would be much helpful if the solution is provided in C#. Thanks in advance.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

From this document, it mentions if all the child nodes are selected, the parent node also becomes selected. It is by design. If you want the selected nodes only contains the child nodes, you could try to traverse the SelectedNodes, when the node is equal to parent node, then remove it.

0 Votes 0 ·

Hi, I tried what you told but removing parent node from SelectedNodes removes its child node too.

0 Votes 0 ·
FayWang-MSFT avatar image FayWang-MSFT buddingdeveloper-3601 ·

Yes, it is an expected behavior, when the parent node is removed from SelectedNodes, this means unselect all child nodes, so its child nodes will also be removed from SelectedNodes, it is by design. I may not have made it clear before, what I mean is you can create a new List<TreeViewNode> and then traverse the SelectedNodes, when the node is equal to child node, you can add the node into the new list. After that, you can use the new list to do what you want.

0 Votes 0 ·
Show more comments

0 Answers