Exemple #1
0
        private void treeView_lib_f2_DoubleClick(object sender, EventArgs e)
        {
            //Sets node as selected node, after this you can also select signals from a device
            //In the future, want to add it to a list instead of just 1 node at a time
            TreeView   treeView      = sender as TreeView;
            MyTreeNode selected_Node = (MyTreeNode)treeView.SelectedNode;

            lbl_list.Text = "SELECTED: \n" + selected_Node.nNode.sNode;
            MyTreeNode newNode = new MyTreeNode(selected_Node.nNode);

            newNode.Text = newNode.nNode.sNode;
            newNode      = (MyTreeNode)selected_Node.Clone();

            if ((pNode.nNode.GetClass() == "Device" && newNode.nNode.GetClass() != "Signal") || (pNode.nNode.GetClass() == "Node" && newNode.nNode.GetClass() == "Signal") || (pNode.nNode.GetClass() == "Signal"))
            {
                return;
            }
            if (newNode.nNode.GetClass() == "Device")
            {
                Device d = (Device)newNode.nNode;
                clBox.Items.Clear();
                foreach (Signal s in d.Signals)
                {
                    l.Add(s);
                    clBox.Items.Add(s.sNode);
                }

                d.Signals.Clear();
                newNode.nNode = d;
                newNode.Nodes.Clear();
            }
            addedNode = newNode;
            Ln.Add(newNode);
        }
Exemple #2
0
        private void treeView_lib_f2_DragDrop(object sender, DragEventArgs e)
        {
            TreeView treeView = sender as TreeView;

            // Retrieve the client coordinates of the drop location.
            Point targetPoint = treeView.PointToClient(new Point(e.X, e.Y));

            // Retrieve the node at the drop location.
            MyTreeNode targetNode = (MyTreeNode)treeView.GetNodeAt(targetPoint);

            // Retrieve the node that was dragged.
            MyTreeNode draggedNode = (MyTreeNode)e.Data.GetData(typeof(MyTreeNode));

            // Confirm that the node at the drop location is not
            // the dragged node or a descendant of the dragged node.
            if (targetNode == null)
            {
                targetNode = (MyTreeNode)treeView.Nodes[0];                     //als jij niet op een node sleept, targetNode wordt rootnode
            }
            if (!draggedNode.Equals(targetNode) && !ContainsNode(draggedNode, targetNode))
            {
                // If it is a move operation, remove the node from its current
                // location and add it to the node at the drop location.
                if (e.Effect == DragDropEffects.Move)
                {
                    draggedNode.Remove();
                    targetNode.Nodes.Add(draggedNode);
                }

                // If it is a copy operation, clone the dragged node
                // and add it to the node at the drop location.
                else if (e.Effect == DragDropEffects.Copy)
                {
                    targetNode.Nodes.Add((MyTreeNode)draggedNode.Clone());
                }

                // Expand the node at the location
                // to show the dropped node.
                targetNode.Expand();
            }
        }