During run-time we may be required to copy the content of a treeview into another treeview programmatically
Let us suppose there are two treeviews (treeview1 and treeview2) and a button (button1) in a form. In the button-click event one program file will be called which copies the content of treeview1 to treeview2.
Button-Click event:
DO copytree WITH this.parent.treeview1, this.parent.treeview2 //This code calls a program file(copytree.prg) and passes two treeviews as a parameter copytree.prg: PARAMETERS objTVSrc, objTVDest objTVDest.Nodes.Clear //Deletes all the nodes of the treeview1 before coping For Each lonode In objTVSrc.Nodes WITH lonode If ISNULL(lonode.Parent) objtvdest.nodes.Add(,1, .Key, .Text) //adds root nodes to the treeview2 ELSE objtvdest.nodes.add(.parent.key,4,.key,.text) // adds child nodes in treeview2 EndIf ENDWITH ENDFOR