public MultiSelectTreeNode FindNextNode(MultiSelectTreeNode node)
        {
            if (node != null)
            {
                TreeNode nodep = node.Parent;
                if (node.IsExpanded && node.Nodes.Count != 0)
                {
                    return node.Nodes[0] as MultiSelectTreeNode;
                }
                if (nodep != null)
                {
                    int i = nodep.Nodes.IndexOf(node as TreeNode);

                    if (nodep.Nodes.Count > i + 1)
                    {
                        return nodep.Nodes[i + 1] as MultiSelectTreeNode;
                    }
                    else
                    {
                        if (nodep.Parent != null)
                        {
                            return FindNextNode(nodep as MultiSelectTreeNode);
                        }
                    }
                }
            }
            return null;
        }
 public void AddSelectedNode(MultiSelectTreeNode node)
 {
     selectedNodes.Add(node);
     node.Select(false);
     TreeViewEventArgs e = new TreeViewEventArgs(node);
     OnAfterSelect(e);
 }
        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();
                    }
                }
            }
        }
Esempio n. 4
0
        private void UnselectNodesRecursively(MultiSelectTreeNode tn, TreeViewAction tva)
        {
            SelectNode(tn, false, tva);

            foreach (MultiSelectTreeNode node in tn.Nodes)
            {
                UnselectNodesRecursively(node, tva);
            }
        }
Esempio n. 5
0
 protected override void OnMouseDown(MouseEventArgs e)
 {
     LastMouseDownEventPosition = new Point(e.X, e.Y);
     _keysStartNode = null;
     intMouseClicks = e.Clicks;
     MultiSelectTreeNode nodeAt = (MultiSelectTreeNode)base.GetNodeAt(e.X, e.Y);
     if (nodeAt != null)
     {
         if (!IsPlusMinusClicked(nodeAt, e) && (nodeAt != null) && IsClickOnNode(nodeAt, e) && !IsNodeSelected(nodeAt))
         {
             _nodeProcessedOnMouseDown = true;
             ProcessNodeRange(_mostRecentSelectedNode, nodeAt, e, Control.ModifierKeys, TreeViewAction.ByMouse, true);
         }
         base.OnMouseDown(e);
     }
 }
Esempio n. 6
0
 private void UnselectAllNodesNotBelongingToParent(MultiSelectTreeNode parent, TreeViewAction tva)
 {
     ArrayList list = new ArrayList();
     foreach (MultiSelectTreeNode node in _selectedNodes)
     {
         if (!IsChildOf(node, parent))
         {
             list.Add(node);
         }
     }
     foreach (MultiSelectTreeNode node2 in list)
     {
         SelectNode(node2, false, tva);
     }
 }
Esempio n. 7
0
 private void UnselectNodesOutsideRange(MultiSelectTreeNode startNode, MultiSelectTreeNode endNode, TreeViewAction tva)
 {
     if (startNode != null && endNode != null)
     {
         MultiSelectTreeNode node = null;
         MultiSelectTreeNode node2 = null;
         if (startNode.Bounds.Y < endNode.Bounds.Y)
         {
             node = startNode;
             node2 = endNode;
         }
         else
         {
             node = endNode;
             node2 = startNode;
         }
         MultiSelectTreeNode tn = node;
         while (tn != null)
         {
             tn = tn.PrevVisibleNode;
             if (tn != null)
             {
                 SelectNode(tn, false, tva);
             }
         }
         tn = node2;
         while (tn != null)
         {
             tn = tn.NextVisibleNode;
             if (tn != null)
             {
                 SelectNode(tn, false, tva);
             }
         }
     }
 }
Esempio n. 8
0
        public void UpdateCheckboxVisibility(MultiSelectTreeNode treeNode)
        {
            if (CheckBoxes && treeNode.Handle != IntPtr.Zero && Handle != IntPtr.Zero)
            {
                NativeMethods.TVITEM tvItem = new NativeMethods.TVITEM();
                tvItem.hItem = treeNode.Handle;
                tvItem.mask = NativeMethods.TVIF_STATE;
                tvItem.stateMask = NativeMethods.TVIS_STATEIMAGEMASK;
                tvItem.state = 0;

                if (treeNode.ShowCheckBox && treeNode.Checked)
                {
                    tvItem.state = 2 << 12;
                }
                else if (treeNode.ShowCheckBox)
                {
                    tvItem.state = 1 << 12;
                }

                IntPtr lparam = Marshal.AllocHGlobal(Marshal.SizeOf(tvItem));
                Marshal.StructureToPtr(tvItem, lparam, false);
                Win32.SendMessage(Handle, NativeMethods.TVM_SETITEM, IntPtr.Zero, lparam);
            }
        }
Esempio n. 9
0
        private void UnselectAllNodesExceptNode(MultiSelectTreeNode nodeKeepSelected, TreeViewAction tva)
        {
            List<MultiSelectTreeNode> list = new List<MultiSelectTreeNode>();

            foreach (MultiSelectTreeNode node in _selectedNodes)
            {
                if (nodeKeepSelected == null)
                {
                    list.Add(node);
                }
                else if ((nodeKeepSelected != null) && (node != nodeKeepSelected))
                {
                    list.Add(node);
                }
            }
            foreach (MultiSelectTreeNode node2 in list)
            {
                SelectNode(node2, false, tva);
            }
        }
 public void RemoveSelectedNode(MultiSelectTreeNode node)
 {
     selectedNodes.Remove(node);
     node.UnSelect(false);
     TreeViewEventArgs e = new TreeViewEventArgs(node);
     OnAfterSelect(e);
 }
Esempio n. 11
0
 public int GetNodeLevel(MultiSelectTreeNode node)
 {
     int num = 0;
     while ((node = node.Parent) != null)
     {
         num++;
     }
     return num;
 }
Esempio n. 12
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            Keys none = Keys.None;
            switch (e.Modifiers)
            {
                case Keys.Shift:
                case Keys.Control:
                case (Keys.Control | Keys.Shift):
                    none = Keys.Shift;
                    if (_keysStartNode == null)
                    {
                        _keysStartNode = _mostRecentSelectedNode;
                    }
                    break;

                default:
                    _keysStartNode = null;
                    break;
            }
            int intNumber = 0;
            MultiSelectTreeNode endNode = null;
            switch (e.KeyCode)
            {
                case Keys.Prior:
                    intNumber = GetNumberOfVisibleNodes();
                    endNode = GetNextTreeNode(_mostRecentSelectedNode, false, intNumber);
                    break;

                case Keys.Next:
                    intNumber = GetNumberOfVisibleNodes();
                    endNode = GetNextTreeNode(_mostRecentSelectedNode, true, intNumber);
                    break;

                case Keys.End:
                    endNode = GetLastVisibleNode();
                    break;

                case Keys.Home:
                    endNode = Nodes[0];
                    break;

                case Keys.Left:
                    if (_mostRecentSelectedNode.IsExpanded)
                        _mostRecentSelectedNode.Collapse();
                    else
                        endNode = _mostRecentSelectedNode.Parent;
                    break;

                case Keys.Up:
                    endNode = _mostRecentSelectedNode.PrevVisibleNode;
                    break;

                case Keys.Right:
                    if (_mostRecentSelectedNode.IsExpanded)
                    {
                        endNode = _mostRecentSelectedNode.NextVisibleNode;
                        if (endNode != null && !endNode.Parent.Equals(_mostRecentSelectedNode))
                            endNode = null;
                    }
                    else
                        _mostRecentSelectedNode.Expand();
                    break;

                case Keys.Down:
                    endNode = _mostRecentSelectedNode.NextVisibleNode;
                    break;

                default:
                    base.OnKeyDown(e);
                    return;
            }
            if (endNode != null)
            {
                ProcessNodeRange(_keysStartNode, endNode, new MouseEventArgs(MouseButtons.Left, 1, Cursor.Position.X, Cursor.Position.Y, 0), none, TreeViewAction.ByKeyboard, false);
                _mostRecentSelectedNode = endNode;
            }
            if (_mostRecentSelectedNode != null)
            {
                MultiSelectTreeNode tnMostRecentSelectedNode = null;
                switch (e.KeyCode)
                {
                    case Keys.Prior:
                        tnMostRecentSelectedNode = GetNextTreeNode(_mostRecentSelectedNode, false, intNumber - 2);
                        break;

                    case Keys.Next:
                        tnMostRecentSelectedNode = GetNextTreeNode(_mostRecentSelectedNode, true, intNumber - 2);
                        break;

                    case Keys.End:
                    case Keys.Home:
                        tnMostRecentSelectedNode = _mostRecentSelectedNode;
                        break;

                    case Keys.Up:
                        tnMostRecentSelectedNode = GetNextTreeNode(_mostRecentSelectedNode, false, 5);
                        break;

                    case Keys.Down:
                        tnMostRecentSelectedNode = GetNextTreeNode(_mostRecentSelectedNode, true, 5);
                        break;
                }
                if (tnMostRecentSelectedNode != null)
                {
                    if (((e.KeyData & Keys.Control) != 0) || ((e.KeyData & Keys.Shift) != 0))
                    {
                        SuspendLayout();
                        int prevScrollPos = HScrollPos;
                        tnMostRecentSelectedNode.EnsureVisible();
                        HScrollPos = prevScrollPos;
                        ResumeLayout();
                    }
                    else
                    {
                        tnMostRecentSelectedNode.EnsureVisible();
                    }
                }
            }
            base.OnKeyDown(e);
        }
        private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            // Check for multiple selection support.
            MultiSelectTreeNode multiNode = e.Node as MultiSelectTreeNode;

            if (multiNode != null)
            {
                // Retrieve the node font. If the node font has not been set,
                // use the TreeView font.
                Font nodeFont = multiNode.NodeFont;
                if (nodeFont == null)
                {
                    nodeFont = ((TreeView)sender).Font;
                }

                // Create brushes for the background and foreground.
                Brush backBrush, foreBrush;
                if (multiNode.IsSelected)
                {
                    foreBrush = SystemBrushes.HighlightText;
                    backBrush = SystemBrushes.Highlight;
                }
                else
                {
                    if (multiNode.ForeColor != Color.Empty)
                    {
                        foreBrush = new SolidBrush(multiNode.ForeColor);
                    }
                    else
                    {
                        foreBrush = new SolidBrush(multiNode.TreeView.ForeColor);
                    }
                    if (multiNode.BackColor != Color.Empty)
                    {
                        backBrush = new SolidBrush(multiNode.BackColor);
                    }
                    else
                    {
                        backBrush = new SolidBrush(multiNode.TreeView.BackColor);
                    }
                }

                // Draw the background of the selected node.
                Rectangle bounds = e.Bounds;
                bounds.X += 1;
                e.Graphics.FillRectangle(backBrush, bounds);

                // Draw the node text.
                e.Graphics.DrawString(e.Node.Text, nodeFont, foreBrush, e.Bounds.X, e.Bounds.Y);

                // If the node has focus, draw the focus rectangle.
                if ((e.State & TreeNodeStates.Focused) != 0)
                {
                    using (Pen focusPen = new Pen(Color.Black))
                    {
                        focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                        Rectangle focusBounds = e.Bounds;
                        focusBounds.Size = new Size(focusBounds.Width,
                                                    focusBounds.Height - 1);

                        e.Graphics.DrawRectangle(focusPen, focusBounds);
                    }
                }

                // Dispose brushes if they were created
                // just for this node.
                if (!multiNode.IsSelected)
                {
                    backBrush.Dispose();
                    foreBrush.Dispose();
                }
            }
            else
            {
                // No multiple selection support.
                e.DrawDefault = true;
            }
        }
Esempio n. 14
0
 private bool IsPlusMinusClicked(MultiSelectTreeNode node, MouseEventArgs e)
 {
     return e.X < (20 + (GetNodeLevel(node) * 20)) - HScrollPos;
 }
Esempio n. 15
0
 private bool IsNodeSelected(MultiSelectTreeNode node)
 {
     return node != null && _selectedNodes.Contains(node);
 }
Esempio n. 16
0
 private bool IsClickOnNode(MultiSelectTreeNode node, MouseEventArgs e)
 {
     return node != null && e.X < node.Bounds.X + node.Bounds.Width;
 }
Esempio n. 17
0
 private bool IsChildOf(MultiSelectTreeNode child, MultiSelectTreeNode parent)
 {
     for (MultiSelectTreeNode node = child; node != null; node = node.Parent)
     {
         if (node == parent)
         {
             return true;
         }
     }
     return false;
 }
Esempio n. 18
0
 public MultiSelectTreeNode GetRootParent(MultiSelectTreeNode child)
 {
     MultiSelectTreeNode parent = child;
     while (parent.Parent != null)
     {
         parent = parent.Parent;
     }
     return parent;
 }
 public MultiSelectTreeNode FindPrevNode(MultiSelectTreeNode node)
 {
     if (node != null)
     {
         TreeNode nodep = node.Parent;
         if (nodep != null)
         {
             int i = nodep.Nodes.IndexOf(node);
             if (i > 0)
             {
                 return nodep.Nodes[i - 1] as MultiSelectTreeNode;
             }
             else
             {
                 return nodep as MultiSelectTreeNode;
             }
         }
     }
     return null;
 }
Esempio n. 20
0
        /// <summary>
        /// Processes a node range.
        /// </summary>
        /// <param name="startNode">Start node of range.</param>
        /// <param name="endNode">End node of range.</param>
        /// <param name="e">MouseEventArgs.</param>
        /// <param name="keys">Keys.</param>
        /// <param name="tva">TreeViewAction.</param>
        /// <param name="allowStartEdit">True if node can go to edit mode, false if not.</param>
        private void ProcessNodeRange(MultiSelectTreeNode startNode, MultiSelectTreeNode endNode, MouseEventArgs e, Keys keys, TreeViewAction tva, bool allowStartEdit)
        {
            _selectionChanged = false; // prepare for OnSelectionsChanged

            if (e.Button == MouseButtons.Left)
            {
                _wasDoubleClick = (intMouseClicks == 2);

                MultiSelectTreeNode tnTemp = null;
                int intNodeLevelStart;

                if (((keys & Keys.Control) == 0) && ((keys & Keys.Shift) == 0))
                {
                    // CTRL and SHIFT not held down							
                    _selectionMirrorPoint = endNode;
                    int intNumberOfSelectedNodes = SelectedNodes.Count;

                    // If it was a double click, select node and suspend further processing					
                    if (_wasDoubleClick)
                    {
                        base.OnMouseDown(e);
                        return;
                    }

                    if (!IsPlusMinusClicked(endNode, e))
                    {
                        bool blnNodeWasSelected = false;
                        if (IsNodeSelected(endNode))
                            blnNodeWasSelected = true;


                        UnselectAllNodesExceptNode(endNode, tva);
                        SelectNode(endNode, true, tva);


                        if ((blnNodeWasSelected) && (LabelEdit) && (allowStartEdit) && (!_wasDoubleClick) && (intNumberOfSelectedNodes <= 1))
                        {
                            // Node should be put in edit mode					
                            _nodeToStartEditOn = endNode;
                            System.Threading.ThreadPool.QueueUserWorkItem(StartEdit);
                        }
                    }
                }
                else if (((keys & Keys.Control) != 0) && ((keys & Keys.Shift) == 0))
                {
                    // CTRL held down
                    _selectionMirrorPoint = null;

                    if (!IsNodeSelected(endNode))
                    {
                        switch (_selectionMode)
                        {
                            case TreeViewSelectionMode.SingleSelect:
                                UnselectAllNodesExceptNode(endNode, tva);
                                break;

                            case TreeViewSelectionMode.MultiSelectSameRootBranch:
                                MultiSelectTreeNode tnAbsoluteParent2 = GetRootParent(endNode);
                                UnselectAllNodesNotBelongingToParent(tnAbsoluteParent2, tva);
                                break;

                            case TreeViewSelectionMode.MultiSelectSameLevel:
                                UnselectAllNodesNotBelongingToLevel(GetNodeLevel(endNode), tva);
                                break;

                            case TreeViewSelectionMode.MultiSelectSameLevelAndRootBranch:
                                MultiSelectTreeNode tnAbsoluteParent = GetRootParent(endNode);
                                UnselectAllNodesNotBelongingToParent(tnAbsoluteParent, tva);
                                UnselectAllNodesNotBelongingToLevel(GetNodeLevel(endNode), tva);
                                break;

                            case TreeViewSelectionMode.MultiSelectSameParent:
                                MultiSelectTreeNode tnParent = endNode.Parent;
                                UnselectAllNodesNotBelongingDirectlyToParent(tnParent, tva);
                                break;
                        }

                        SelectNode(endNode, true, tva);
                    }
                    else
                    {
                        SelectNode(endNode, false, tva);
                    }
                }
                else if (((keys & Keys.Control) == 0) && ((keys & Keys.Shift) != 0))
                {
                    // SHIFT pressed
                    if (_selectionMirrorPoint == null)
                    {
                        _selectionMirrorPoint = startNode;
                    }

                    switch (_selectionMode)
                    {
                        case TreeViewSelectionMode.SingleSelect:
                            UnselectAllNodesExceptNode(endNode, tva);
                            SelectNode(endNode, true, tva);
                            break;

                        case TreeViewSelectionMode.MultiSelectSameRootBranch:
                            MultiSelectTreeNode tnAbsoluteParentStartNode = GetRootParent(startNode);
                            tnTemp = startNode;
                            // Check each visible node from startNode to endNode and select it if needed
                            while ((tnTemp != null) && (tnTemp != endNode))
                            {
                                if (startNode.Bounds.Y > endNode.Bounds.Y)
                                    tnTemp = tnTemp.PrevVisibleNode;
                                else
                                    tnTemp = tnTemp.NextVisibleNode;
                                if (tnTemp != null)
                                {
                                    MultiSelectTreeNode tnAbsoluteParent = GetRootParent(tnTemp);
                                    if (tnAbsoluteParent == tnAbsoluteParentStartNode)
                                    {
                                        SelectNode(tnTemp, true, tva);
                                    }
                                }
                            }
                            UnselectAllNodesNotBelongingToParent(tnAbsoluteParentStartNode, tva);
                            UnselectNodesOutsideRange(_selectionMirrorPoint, endNode, tva);
                            break;

                        case TreeViewSelectionMode.MultiSelectSameLevel:
                            intNodeLevelStart = GetNodeLevel(startNode);
                            tnTemp = startNode;
                            // Check each visible node from startNode to endNode and select it if needed
                            while ((tnTemp != null) && (tnTemp != endNode))
                            {
                                if (startNode.Bounds.Y > endNode.Bounds.Y)
                                    tnTemp = tnTemp.PrevVisibleNode;
                                else
                                    tnTemp = tnTemp.NextVisibleNode;
                                if (tnTemp != null)
                                {
                                    int intNodeLevel = GetNodeLevel(tnTemp);
                                    if (intNodeLevel == intNodeLevelStart)
                                    {
                                        SelectNode(tnTemp, true, tva);
                                    }
                                }
                            }
                            UnselectAllNodesNotBelongingToLevel(intNodeLevelStart, tva);
                            UnselectNodesOutsideRange(_selectionMirrorPoint, endNode, tva);
                            break;

                        case TreeViewSelectionMode.MultiSelectSameLevelAndRootBranch:
                            MultiSelectTreeNode tnAbsoluteParentStart = GetRootParent(startNode);
                            intNodeLevelStart = GetNodeLevel(startNode);
                            tnTemp = startNode;
                            // Check each visible node from startNode to endNode and select it if needed
                            while ((tnTemp != null) && (tnTemp != endNode))
                            {
                                if (startNode.Bounds.Y > endNode.Bounds.Y)
                                    tnTemp = tnTemp.PrevVisibleNode;
                                else
                                    tnTemp = tnTemp.NextVisibleNode;
                                if (tnTemp != null)
                                {
                                    int intNodeLevel = GetNodeLevel(tnTemp);
                                    MultiSelectTreeNode tnAbsoluteParent = GetRootParent(tnTemp);
                                    if ((intNodeLevel == intNodeLevelStart) && (tnAbsoluteParent == tnAbsoluteParentStart))
                                    {
                                        SelectNode(tnTemp, true, tva);
                                    }
                                }
                            }
                            UnselectAllNodesNotBelongingToParent(tnAbsoluteParentStart, tva);
                            UnselectAllNodesNotBelongingToLevel(intNodeLevelStart, tva);
                            UnselectNodesOutsideRange(_selectionMirrorPoint, endNode, tva);
                            break;

                        case TreeViewSelectionMode.MultiSelect:
                            SelectNodesInsideRange(_selectionMirrorPoint, endNode, tva);
                            UnselectNodesOutsideRange(_selectionMirrorPoint, endNode, tva);
                            break;

                        case TreeViewSelectionMode.MultiSelectSameParent:
                            MultiSelectTreeNode tnParentStartNode = startNode.Parent;
                            tnTemp = startNode;
                            // Check each visible node from startNode to endNode and select it if needed
                            while ((tnTemp != null) && (tnTemp != endNode))
                            {
                                if (startNode.Bounds.Y > endNode.Bounds.Y)
                                    tnTemp = tnTemp.PrevVisibleNode;
                                else
                                    tnTemp = tnTemp.NextVisibleNode;
                                if (tnTemp != null)
                                {
                                    MultiSelectTreeNode tnParent = tnTemp.Parent;
                                    if (tnParent == tnParentStartNode)
                                    {
                                        SelectNode(tnTemp, true, tva);
                                    }
                                }
                            }
                            UnselectAllNodesNotBelongingDirectlyToParent(tnParentStartNode, tva);
                            UnselectNodesOutsideRange(_selectionMirrorPoint, endNode, tva);
                            break;
                    }
                }
                else if (((keys & Keys.Control) != 0) && ((keys & Keys.Shift) != 0))
                {
                    // SHIFT AND CTRL pressed
                    switch (_selectionMode)
                    {
                        case TreeViewSelectionMode.SingleSelect:
                            UnselectAllNodesExceptNode(endNode, tva);
                            SelectNode(endNode, true, tva);
                            break;

                        case TreeViewSelectionMode.MultiSelectSameRootBranch:
                            MultiSelectTreeNode tnAbsoluteParentStartNode = GetRootParent(startNode);
                            tnTemp = startNode;
                            // Check each visible node from startNode to endNode and select it if needed
                            while ((tnTemp != null) && (tnTemp != endNode))
                            {
                                if (startNode.Bounds.Y > endNode.Bounds.Y)
                                    tnTemp = tnTemp.PrevVisibleNode;
                                else
                                    tnTemp = tnTemp.NextVisibleNode;
                                if (tnTemp != null)
                                {
                                    MultiSelectTreeNode tnAbsoluteParent = GetRootParent(tnTemp);
                                    if (tnAbsoluteParent == tnAbsoluteParentStartNode)
                                    {
                                        SelectNode(tnTemp, true, tva);
                                    }
                                }
                            }
                            UnselectAllNodesNotBelongingToParent(tnAbsoluteParentStartNode, tva);
                            break;

                        case TreeViewSelectionMode.MultiSelectSameLevel:
                            intNodeLevelStart = GetNodeLevel(startNode);
                            tnTemp = startNode;
                            // Check each visible node from startNode to endNode and select it if needed
                            while ((tnTemp != null) && (tnTemp != endNode))
                            {
                                if (startNode.Bounds.Y > endNode.Bounds.Y)
                                    tnTemp = tnTemp.PrevVisibleNode;
                                else
                                    tnTemp = tnTemp.NextVisibleNode;
                                if (tnTemp != null)
                                {
                                    int intNodeLevel = GetNodeLevel(tnTemp);
                                    if (intNodeLevel == intNodeLevelStart)
                                    {
                                        SelectNode(tnTemp, true, tva);
                                    }
                                }
                            }
                            UnselectAllNodesNotBelongingToLevel(intNodeLevelStart, tva);
                            break;

                        case TreeViewSelectionMode.MultiSelectSameLevelAndRootBranch:
                            MultiSelectTreeNode tnAbsoluteParentStart = GetRootParent(startNode);
                            intNodeLevelStart = GetNodeLevel(startNode);
                            tnTemp = startNode;
                            // Check each visible node from startNode to endNode and select it if needed
                            while ((tnTemp != null) && (tnTemp != endNode))
                            {
                                if (startNode.Bounds.Y > endNode.Bounds.Y)
                                    tnTemp = tnTemp.PrevVisibleNode;
                                else
                                    tnTemp = tnTemp.NextVisibleNode;
                                if (tnTemp != null)
                                {
                                    int intNodeLevel = GetNodeLevel(tnTemp);
                                    MultiSelectTreeNode tnAbsoluteParent = GetRootParent(tnTemp);
                                    if ((intNodeLevel == intNodeLevelStart) && (tnAbsoluteParent == tnAbsoluteParentStart))
                                    {
                                        SelectNode(tnTemp, true, tva);
                                    }
                                }
                            }
                            UnselectAllNodesNotBelongingToParent(tnAbsoluteParentStart, tva);
                            UnselectAllNodesNotBelongingToLevel(intNodeLevelStart, tva);
                            break;

                        case TreeViewSelectionMode.MultiSelect:
                            tnTemp = startNode;
                            // Check each visible node from startNode to endNode and select it if needed
                            while ((tnTemp != null) && (tnTemp != endNode))
                            {
                                if (startNode.Bounds.Y > endNode.Bounds.Y)
                                    tnTemp = tnTemp.PrevVisibleNode;
                                else
                                    tnTemp = tnTemp.NextVisibleNode;
                                if (tnTemp != null)
                                {
                                    SelectNode(tnTemp, true, tva);
                                }
                            }
                            break;

                        case TreeViewSelectionMode.MultiSelectSameParent:
                            MultiSelectTreeNode tnParentStartNode = startNode.Parent;
                            tnTemp = startNode;
                            // Check each visible node from startNode to endNode and select it if needed
                            while ((tnTemp != null) && (tnTemp != endNode))
                            {
                                if (startNode.Bounds.Y > endNode.Bounds.Y)
                                    tnTemp = tnTemp.PrevVisibleNode;
                                else
                                    tnTemp = tnTemp.NextVisibleNode;
                                if (tnTemp != null)
                                {
                                    MultiSelectTreeNode tnParent = tnTemp.Parent;
                                    if (tnParent == tnParentStartNode)
                                    {
                                        SelectNode(tnTemp, true, tva);
                                    }
                                }
                            }
                            UnselectAllNodesNotBelongingDirectlyToParent(tnParentStartNode, tva);
                            break;
                    }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                // if right mouse button clicked, clear selection and select right-clicked node
                if (!IsNodeSelected(endNode))
                {
                    UnselectAllNodes(tva);
                    SelectNode(endNode, true, tva);
                }
            }
            OnSelectionsChanged();
        }
Esempio n. 21
0
        private bool SelectNode(MultiSelectTreeNode node, bool select, TreeViewAction tva)
        {
            bool selected = false;
            if (node == null)
            {
                return false;
            }
            if (select)
            {
                if (!IsNodeSelected(node))
                {
                    MultiSelectTreeViewCancelEventArgs e = new MultiSelectTreeViewCancelEventArgs(node, false, tva);
                    OnBeforeSelect(e);
                    if (e.Cancel)
                    {
                        return false;
                    }
                    _selectedNodes.Add(node);
                    selected = true;
                    _selectionChanged = true;
                    OnAfterSelect(new TreeViewEventArgs(node, tva));
                }
                _mostRecentSelectedNode = node;
                return selected;
            }
            if (IsNodeSelected(node))
            {
                OnBeforeDeselect(new TreeViewEventArgs(node));
                _selectedNodes.Remove(node);
                _selectionChanged = true;

                OnAfterDeselect(new TreeViewEventArgs(node));
            }
            return selected;
        }
Esempio n. 22
0
 private void SelectNodesInsideRange(MultiSelectTreeNode startNode, MultiSelectTreeNode endNode, TreeViewAction tva)
 {
     if (startNode != null && endNode != null)
     {
         MultiSelectTreeNode firstNode = null;
         MultiSelectTreeNode lastNode = null;
         if (startNode.Bounds.Y < endNode.Bounds.Y)
         {
             firstNode = startNode;
             lastNode = endNode;
         }
         else
         {
             firstNode = endNode;
             lastNode = startNode;
         }
         SelectNode(firstNode, true, tva);
         MultiSelectTreeNode nextVisibleNode = firstNode;
         while (nextVisibleNode != lastNode && nextVisibleNode != null)
         {
             nextVisibleNode = nextVisibleNode.NextVisibleNode;
             if (nextVisibleNode != null)
             {
                 SelectNode(nextVisibleNode, true, tva);
             }
         }
         SelectNode(lastNode, true, tva);
     }
 }
 public MultiSelectTreeViewCancelEventArgs(MultiSelectTreeNode node, bool cancel, TreeViewAction action)
     : base(cancel)
 {
     _node = node;
     _action = action;
 }
Esempio n. 24
0
 private MultiSelectTreeNode GetNextTreeNode(MultiSelectTreeNode start, bool down, int intNumber)
 {
     int num = 0;
     MultiSelectTreeNode nextVisibleNode = start;
     while (num < intNumber)
     {
         if (down)
         {
             if (nextVisibleNode.NextVisibleNode == null)
             {
                 return nextVisibleNode;
             }
             nextVisibleNode = nextVisibleNode.NextVisibleNode;
         }
         else
         {
             if (nextVisibleNode.PrevVisibleNode == null)
             {
                 return nextVisibleNode;
             }
             nextVisibleNode = nextVisibleNode.PrevVisibleNode;
         }
         num++;
     }
     return nextVisibleNode;
 }