Advertisement
idsystems

CPP_RAD_Ejercicio47

Jun 21st, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. /*ej47_TreeView
  2. Ejemplo del control TreeView */
  3. #include <radc++.h>
  4.  
  5. Form      form1("Tree View - RAD C++ Ejemplo");
  6. Label    label1("Click algun nodo",-1,50,20,300,20,form1);
  7.  
  8. TreeView tree("",AUTO_ID,50,50,300,100,form1); //create treeview
  9.  
  10. Label    label2("Agregar nuevo nodo bajo el seleccionado",-1,50,170,300,20,form1);
  11. TextBox   text1("Nuevo titulo de nodo",AUTO_ID,50,195,300,20,form1);
  12. Button btn_add1("Agregar bajo seleccionado",AUTO_ID,50,220,110,25,form1);
  13. Button btn_add2("Agregar en root",AUTO_ID,170,220,70,25,form1);
  14. Button  btn_rem("Remover seleccionado",AUTO_ID,250,220,100,25,form1);
  15.  
  16. TreeNode root,node1,node2;
  17.  
  18. FormProcedure proc(FormProcArgs);//prototype of form procedure
  19.  
  20. rad_main()
  21.  
  22.     form1.procedure = proc;
  23.  
  24.     //NOTE1: 3rd argument of function addNode is the unique Id of node
  25.     //       which can later be used to track node.
  26.    
  27.     //NOTE2: rootNode is predefined, which means no parent node.
  28.    
  29.     //add two nodes in root
  30.     root =  tree.addNode(rootNode,"Un Leon",      1);
  31.             tree.addNode(rootNode,"Un Tigre",     2);
  32.  
  33.     //add node under the node 'root'
  34.     node1= tree.addNode(root,"Un Elefante",      3);
  35.     //add node under the node 'node1'
  36.     node2= tree.addNode(node1,"Un Elefante Azul", 4);  
  37.    
  38.     //expand the root node    
  39.     root.expand();  //use node.collapse() to close an expanded node
  40.        
  41. rad_end()
  42.  
  43. FormProcedure proc(FormProcArgs) { //implementation of form procedure
  44.     ON_CLOSE() Application.close();
  45.    
  46.     //some node selected
  47.     ON_NODE_CHANGE(tree) {
  48.         label1.caption = tree.selectedNodeText;
  49.         //to track by Id use
  50.         //if(tree.selecteNodeId == 4) //assumed 4 as your node Id
  51.     }
  52.    
  53.     //check specific node if it has been selected, e.g. node1
  54.     ON_NODE_SELECT(tree, node1) {
  55.         label1.caption = "'node1' ha sido clickeado";
  56.     }        
  57.    
  58.     //add new node under selected one (at runtime)
  59.     ON_COMMAND_BY(btn_add1) {
  60.         //first get the selected node
  61.         TreeNode tempNode = tree.selectedNode;
  62.         tempNode.addNode(text1.text,AUTO_ID);
  63.         tempNode.expand();
  64.     }
  65.  
  66.     //add new node in root
  67.     ON_COMMAND_BY(btn_add2) {
  68.         root = tree.addNode(rootNode,text1.text,AUTO_ID);
  69.     }
  70.    
  71.     //remove the selected node
  72.     ON_COMMAND_BY(btn_rem) {
  73.         if(tree.total == 0) return 0; //no node in treeview
  74.         //first get the selected node
  75.         TreeNode tempNode = tree.selectedNode;
  76.         //now remove it
  77.         tempNode.remove();
  78.     }        
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement