Row Parent Node

Originally Posted 4 October 2016, 3:52 pm EST

  • Originally Posted 4 October 2016, 3:52 pm EST

    I would like get the parent node row index for a non-Node row. My method is iterate the Nodes and check the row index. In the code below, I assume there is only one level node. I wonder if there any more direct and efficient way. Thanks.
    int GetParentNode(int rowIndex)
    int nodeIndex = -1;
    foreach (Node node in fgMarket.Nodes)
    if (node.Row.Index < rowIndex)
    nodeIndex = node.Row.Index;
    return nodeIndex;
  • Reply


    Thanks for providing the code snippet.

    For getting the index of the parent node, apart from traversing through loop there is one another way, which is far more efficient too.
    You could use the "GetNode()" of the node and also calculate it for Parent as "NodeTypeEnum.Parent" and capture its row and eventually its index.
    Please refer to the following code snippet for reference:
       //row is any row object

    row.IsNode = true;
    var node = row.Node;
    Node parent = node.GetNode(NodeTypeEnum.Parent);
    Row r = parent.Row;
    int parentIndex = r.Index;

    Attached is the sample application implementing the same. You just need to click on any row and it will show you the index of root node and also the index of parent node. It will also work for multilevel nodes.

    Best Regards,
Need extra support?

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

Learn More

Forum Channels