tree_move_node
Description
Move seleted row to the position.
Syntax
bool tree_move_node( TreeNode & tr, int nRow, int nPosition = -1, DWORD dwCntrl = 0, LPCSTR lpcszAttribute = NULL )
Parameters
- tr
- [modify] source tree,
- nRow
- [Input] the seleted row treenode will move.
- nPosition
- [Input] the position of the seleted row will move.
- dwCntrl
- [Input]rule for getting tree node, See TREENODEAddGetRules
- lpcszAttribute
- [Input]work with dwCntrl, See TREENODEAddGetRules
Return
success return true, else false;
Examples
EX1
int tree_move_node_ex1()
{
Tree myTree;
TreeNode tn1,tn2,tn3;
tn1 = myTree.AddNumericNode(123,"node1", 1);
tn2 = myTree.AddTextNode("abc","node2", 2);
tn3 = myTree.AddNumericNode(345,"node3", 3);
myTree.node4.First.strVal = "dd";
myTree.node4.Second.strVal = "a";
myTree.node4.Third.strVal = "b";
myTree.node4.Fourth.strVal = "c";
myTree.node4.Fith.strVal = "d";
myTree.node4.Third.DataID = 3;
// Source Tree as following:
//|--node1 = 123
//|--node2 = abc
//|--node3 = 345
//|--node4
//|----First = dd
//|----Second = a
//|----Third = b
//|----Fourth = c
//|----Fith = d
//out_tree(myTree);
//Normal case.
bool bRet = tree_move_node(myTree, 6,2);
//|--node1 = 123
//|--node2 = abc
//|--Third = b
//|--node3 = 345
//|--node4
//|----First = dd
//|----Second = a
//|----Fourth = c
//|----Fith = d
ASSERT(bRet);
ASSERT(strcmp(myTree.Third.strVal, tree_get_node(myTree, 2).strVal) == 0);
//out_tree(myTree);
//Add begin
bRet = tree_move_node(myTree, 2,0);
//|--Third = b
//|--node1 = 123
//|--node2 = abc
//|--node3 = 345
//|--node4
//|----First = dd
//|----Second = a
//|----Fourth = c
//|----Fith = d
ASSERT(bRet);
ASSERT(strcmp(myTree.Third.strVal, myTree.FirstNode.strVal) == 0 );
//out_tree(myTree);
//Add at the end
bRet = tree_move_node(myTree, 3,-1);
//|--Third = b
//|--node1 = 123
//|--node2 = abc
//|--node4
//|----First = dd
//|----Second = a
//|----Fourth = c
//|----Fith = d
//|--node3 = 345
ASSERT(bRet);
ASSERT(myTree.node3.nVal == myTree.LastNode.nVal);
//out_tree(myTree);
//not work, return false;
bRet = tree_move_node(myTree, 3,10);
ASSERT(!bRet);
///Result
//|--Third = b
//|--node1 = 123
//|--node2 = abc
//|--node4
//|----First = dd
//|----Second = a
//|----Fourth = c
//|----Fith = d
//|--node3 = 345
///Invalid case nRow <0
bRet = tree_move_node(myTree, -1,2);
ASSERT(!bRet);
///Invalid case nRow > treenode rows.
bRet = tree_move_node(myTree, 10,5);
ASSERT(!bRet);
return 1;
}
Remark
See Also
tree_get_node
header to Include
origin.h
Reference
|