Example #1
0
        private void CustomTreeView_Load(object sender, EventArgs e)
        {
            MultiSelectTreeNode2 nodeP = new MultiSelectTreeNode2("Node Group");

            multiSelectTreeView1.Nodes.Add(nodeP);

            MultiSelectTreeNode2 node = new MultiSelectTreeNode2("First Node");

            node.Select();
            nodeP.Nodes.Add(node);
            node = new MultiSelectTreeNode2("Second Node");
            nodeP.Nodes.Add(node);
            node = new MultiSelectTreeNode2("Third Node");
            nodeP.Nodes.Add(node);
            node = new MultiSelectTreeNode2("Fourth Node");
            nodeP.Nodes.Add(node);
            node = new MultiSelectTreeNode2("Fifth Node");
            nodeP.Nodes.Add(node);
            node = new MultiSelectTreeNode2("Sixth Node");
            nodeP.Nodes.Add(node);
            node = new MultiSelectTreeNode2("Seventh Node");
            nodeP.Nodes.Add(node);

            multiSelectTreeView1.ExpandAll();
        }
        protected override void OnNodeMouseClick(TreeNodeMouseClickEventArgs e)
        {
            TreeNode nodeHit = base.HitTest(e.X, e.Y).Node;

            if (nodeHit != null)
            {
                MultiSelectTreeNode2 multiNode = nodeHit as MultiSelectTreeNode2;
                if (multiNode != null)
                {
                    // Use advanced selection rules.
                    if ((Control.ModifierKeys & Keys.Control) == 0)
                    {
                        // Ctrl is not held down.
                        // Remove previous selection.
                        List <MultiSelectTreeNode2> nodesToDelete =
                            new List <MultiSelectTreeNode2>();
                        foreach (MultiSelectTreeNode2 node in selectedNodes)
                        {
                            if (node != multiNode)
                            {
                                nodesToDelete.Add(node);
                            }
                        }
                        foreach (MultiSelectTreeNode2 node in nodesToDelete)
                        {
                            node.UnSelect();
                        }
                    }

                    if (multiNode.IsSelected)
                    {
                        // Node is already selected.
                        // Toggle it off.
                        multiNode.UnSelect();
                    }
                    else
                    {
                        // Add new selection.
                        multiNode.Select();
                    }
                }
            }
        }