C1TreeView: how to get the root node of a certain child node?

Posted by: iamyoukou on 20 June 2024, 10:50 pm EST

    • Post Options:
    • Link

    Posted 20 June 2024, 10:50 pm EST - Updated 20 June 2024, 10:56 pm EST

    Hi, I have a treeview as shown in the image.

    Suppose I selected “Root1 Level2” node.

    Is there any way to get “Root1” node?

    Here is the sample code.

    TreeViewTest.zip

    Best regards

    Youkou

  • Posted 21 June 2024, 6:52 am EST

    Hi Youkou,

    To get the root-level parent node of any selected node, you can write a simple method to iterate all the nodes and find the level-0 node for the selection. Please see the attached sample project showing a simple implementation of the same.

    Attachment: TreeViewTest_Updated.zip

    Best Regards,

    Kartik

  • Posted 23 June 2024, 9:07 pm EST

    Hi Kartik,

    Thank you for the sample code. It works well. The idea of flattening a tree structure into a list, then use Level property to find the root node is quite nice.

    Best regards

    Youkou

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels