tree_get_node_by_dataid

 

Description

Walk all tree nodes and get the tree node with given data id

Syntax

TreeNode tree_get_node_by_dataid( TreeNode & tr, int nDataID, bool bRecursive = false, int nSearchLevel = 0 )

Parameters

tr
[input] the tree node to walk
nDataID
[input] Data ID, saved in STR_DATAID_ATTRIB attribute
bRecursive
[input] true will walk all sub level nodes, false will only check this level
nSearchLevel
[input] if > 0, means do recursion up to nSearchLevel levels. bRecursive can be false.

Return

the TreeNode with given data id if successful. An invalid TreeNode if not sucessful.

Note: If nSearchLevel > 0, recursion to nSearchLevel levels occurs even if is bRecursive false.

See Also: tree_find_node_by_dataID for faster search using parent node data id's and repeat id's.

Examples

EX1

void tree_get_node_by_dataid_ex1()
{
        Tree myTree;
        TreeNode trPh = myTree.AddNode("physics");
        trPh.ExamMonth.strVal = "May";
                
        TreeNode trMath = myTree.AddNode("Math");
        TreeNode trTeacher = trMath.AddTextNode("Danice", "Teather");
        trTeacher.DataID = 1;
        trTeacher.Other1.strVal = "Male";
        trTeacher.Other1.DataID = 3;
                
        TreeNode trCount = trMath.AddNumericNode(100, "Count");
        trCount.DataID = 2;
        trCount.Other2.strVal = "First";
        trCount.Other2.DataID = 4;
        TreeNode trFirst = trMath.AddNumericNode(55, "Hello");
        trFirst.DataID = 5;
        
        TreeNode tn = tree_get_node_by_dataid(myTree, 4, false, 2);
        if( tn )
        {
                out_str("Yes!");
                out_tree(tn);
        }
        else
                out_str("No!");
}

Remark

See Also

tree_find_node_by_dataID

header to Include

origin.h

Reference