Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*ej47_TreeView
- Ejemplo del control TreeView */
- #include <radc++.h>
- Form form1("Tree View - RAD C++ Ejemplo");
- Label label1("Click algun nodo",-1,50,20,300,20,form1);
- TreeView tree("",AUTO_ID,50,50,300,100,form1); //create treeview
- Label label2("Agregar nuevo nodo bajo el seleccionado",-1,50,170,300,20,form1);
- TextBox text1("Nuevo titulo de nodo",AUTO_ID,50,195,300,20,form1);
- Button btn_add1("Agregar bajo seleccionado",AUTO_ID,50,220,110,25,form1);
- Button btn_add2("Agregar en root",AUTO_ID,170,220,70,25,form1);
- Button btn_rem("Remover seleccionado",AUTO_ID,250,220,100,25,form1);
- TreeNode root,node1,node2;
- FormProcedure proc(FormProcArgs);//prototype of form procedure
- rad_main()
- form1.procedure = proc;
- //NOTE1: 3rd argument of function addNode is the unique Id of node
- // which can later be used to track node.
- //NOTE2: rootNode is predefined, which means no parent node.
- //add two nodes in root
- root = tree.addNode(rootNode,"Un Leon", 1);
- tree.addNode(rootNode,"Un Tigre", 2);
- //add node under the node 'root'
- node1= tree.addNode(root,"Un Elefante", 3);
- //add node under the node 'node1'
- node2= tree.addNode(node1,"Un Elefante Azul", 4);
- //expand the root node
- root.expand(); //use node.collapse() to close an expanded node
- rad_end()
- FormProcedure proc(FormProcArgs) { //implementation of form procedure
- ON_CLOSE() Application.close();
- //some node selected
- ON_NODE_CHANGE(tree) {
- label1.caption = tree.selectedNodeText;
- //to track by Id use
- //if(tree.selecteNodeId == 4) //assumed 4 as your node Id
- }
- //check specific node if it has been selected, e.g. node1
- ON_NODE_SELECT(tree, node1) {
- label1.caption = "'node1' ha sido clickeado";
- }
- //add new node under selected one (at runtime)
- ON_COMMAND_BY(btn_add1) {
- //first get the selected node
- TreeNode tempNode = tree.selectedNode;
- tempNode.addNode(text1.text,AUTO_ID);
- tempNode.expand();
- }
- //add new node in root
- ON_COMMAND_BY(btn_add2) {
- root = tree.addNode(rootNode,text1.text,AUTO_ID);
- }
- //remove the selected node
- ON_COMMAND_BY(btn_rem) {
- if(tree.total == 0) return 0; //no node in treeview
- //first get the selected node
- TreeNode tempNode = tree.selectedNode;
- //now remove it
- tempNode.remove();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement