private void OwnerDrawnTreeView_Load(object sender, EventArgs e)
        {
            MultiSelectTreeNode nodeP = new MultiSelectTreeNode("Node Group", selectedNodes);

            treeView1.Nodes.Add(nodeP);

            MultiSelectTreeNode node = new MultiSelectTreeNode("First Node", selectedNodes);

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

            treeView1.ExpandAll();
        }
        private void treeView1_MouseDown(object sender, MouseEventArgs e)
        {
            TreeNode nodeHit = treeView1.HitTest(e.X, e.Y).Node;

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

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