// Constructor.
	public TreeViewCancelEventArgs
				(TreeNode node, bool cancel, TreeViewAction action)
			: base(cancel)
			{
				this.node = node;
				this.action = action;
			}
Ejemplo n.º 2
0
 public VirtualTreeViewCancelEventArgs(VirtualTreeNode node, bool cancel, TreeViewAction action)
     : base(cancel)
 {
     _node = node;
     _action = action;
 }
 private void tvClientesServicios_BeforeCheck(object sender, TreeViewCancelEventArgs e)
 {
     action = e.Action;
 }
Ejemplo n.º 4
0
		/// <summary>
		/// Recursively unselect node.
		/// </summary>
		/// <param name="tn">Node to recursively unselect.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void UnselectNodesRecursively(TreeNode tn, TreeViewAction tva)
		{
			SelectNode(tn, false, tva);
			foreach (TreeNode child in tn.Nodes)
			{
				UnselectNodesRecursively(child, tva);
			}
		}
Ejemplo n.º 5
0
		/// <summary>
		/// Selects nodes within the specified range.
		/// </summary>
		/// <param name="startNode">Start node.</param>
		/// <param name="endNode">End Node.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void SelectNodesInsideRange(TreeNode startNode, TreeNode endNode, TreeViewAction tva)
		{
			// Calculate start node and end node
			TreeNode firstNode = null;
			TreeNode lastNode = null;
			if (startNode.Bounds.Y < endNode.Bounds.Y)
			{
				firstNode = startNode;
				lastNode = endNode;
			}
			else
			{
				firstNode = endNode;
				lastNode = startNode;
			}

			// Select each node in range
			SelectNode(firstNode, true, tva);
			TreeNode tnTemp = firstNode;
			while (tnTemp != lastNode)
			{
				tnTemp = tnTemp.NextVisibleNode;
				if (tnTemp != null)
				{
					SelectNode(tnTemp, true, tva);
				}
			}
			SelectNode(lastNode, true, tva);
		}
Ejemplo n.º 6
0
		/// <summary>
		/// Unselects all selected nodes, except for the specified node which should not be touched.
		/// </summary>
		/// <param name="nodeKeepSelected">Node not to touch.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void UnselectAllNodesExceptNode(TreeNode nodeKeepSelected, TreeViewAction tva)
		{
			// First, build list of nodes that need to be unselected
			ArrayList arrNodesToDeselect = new ArrayList();
			foreach (TreeNode selectedTreeNode in htblSelectedNodes.Values)
			{
				if (nodeKeepSelected == null)
				{
					arrNodesToDeselect.Add(selectedTreeNode);
				}
				else if ((nodeKeepSelected != null) && (selectedTreeNode != nodeKeepSelected))
				{
					arrNodesToDeselect.Add(selectedTreeNode);
				}
			}

			// Do the actual unselect
			foreach (TreeNode tnToDeselect in arrNodesToDeselect)
			{
				SelectNode(tnToDeselect, false, tva);
			}
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Unselects all selected nodes that don't belong to the specified level.
		/// </summary>
		/// <param name="level">Node level.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void UnselectAllNodesNotBelongingToLevel(int level, TreeViewAction tva)
		{
			// First, build list of nodes that need to be unselected
			ArrayList arrNodesToDeselect = new ArrayList();
			foreach (TreeNode selectedTreeNode in htblSelectedNodes.Values)
			{
				if (GetNodeLevel(selectedTreeNode) != level)
				{
					arrNodesToDeselect.Add(selectedTreeNode);
				}
			}

			// Do the actual unselect
			foreach (TreeNode tnToDeselect in arrNodesToDeselect)
			{
				SelectNode(tnToDeselect, false, tva);
			}
		}
Ejemplo n.º 8
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(TreeNode startNode, TreeNode endNode, MouseEventArgs e, Keys keys, TreeViewAction tva, bool allowStartEdit)
		{
			blnSelectionChanged = false; // prepare for OnSelectionsChanged

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

				TreeNode tnTemp = null;
				int intNodeLevelStart;

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

					// If it was a double click, select node and suspend further processing					
					if (blnWasDoubleClick)
					{
						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) && (!blnWasDoubleClick) && (intNumberOfSelectedNodes <= 1))
						{
							// Node should be put in edit mode					
							tnNodeToStartEditOn = endNode;
							System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(StartEdit));
							t.Start();
						}
					}
				}
				else if (((keys & Keys.Control) != 0) && ((keys & Keys.Shift) == 0))
				{
					// CTRL held down
					tnSelectionMirrorPoint = null;

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

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

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

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

							case TreeViewSelectionMode.MultiSelectSameParent:
								TreeNode 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 (tnSelectionMirrorPoint == null)
					{
						tnSelectionMirrorPoint = startNode;
					}

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

						case TreeViewSelectionMode.MultiSelectSameRootBranch:
							TreeNode 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)
								{
									TreeNode tnAbsoluteParent = GetRootParent(tnTemp);
									if (tnAbsoluteParent == tnAbsoluteParentStartNode)
									{
										SelectNode(tnTemp, true, tva);
									}
								}
							}
							UnselectAllNodesNotBelongingToParent(tnAbsoluteParentStartNode, tva);
							UnselectNodesOutsideRange(tnSelectionMirrorPoint, 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(tnSelectionMirrorPoint, endNode, tva);
							break;

						case TreeViewSelectionMode.MultiSelectSameLevelAndRootBranch:
							TreeNode 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);
									TreeNode tnAbsoluteParent = GetRootParent(tnTemp);
									if ((intNodeLevel == intNodeLevelStart) && (tnAbsoluteParent == tnAbsoluteParentStart))
									{
										SelectNode(tnTemp, true, tva);
									}
								}
							}
							UnselectAllNodesNotBelongingToParent(tnAbsoluteParentStart, tva);
							UnselectAllNodesNotBelongingToLevel(intNodeLevelStart, tva);
							UnselectNodesOutsideRange(tnSelectionMirrorPoint, endNode, tva);
							break;

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

						case TreeViewSelectionMode.MultiSelectSameParent:
							TreeNode 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)
								{
									TreeNode tnParent = tnTemp.Parent;
									if (tnParent == tnParentStartNode)
									{
										SelectNode(tnTemp, true, tva);
									}
								}
							}
							UnselectAllNodesNotBelongingDirectlyToParent(tnParentStartNode, tva);
							UnselectNodesOutsideRange(tnSelectionMirrorPoint, 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:
							TreeNode 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)
								{
									TreeNode 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:
							TreeNode 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);
									TreeNode 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:
							TreeNode 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)
								{
									TreeNode 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();
		}
Ejemplo n.º 9
0
 public TreeViewEventArgs(TreeNode node, TreeViewAction action)
 {
     Action = action;
     Node = node;
 }
 internal bool TreeViewBeforeCheck(TreeNode node, TreeViewAction actionTaken)
 {
     TreeViewCancelEventArgs e = new TreeViewCancelEventArgs(node, false, actionTaken);
     this.OnBeforeCheck(e);
     return e.Cancel;
 }
		/// <summary>
		/// Applies the given state to the given node.
		/// Raises events, too.
		/// </summary>
		/// <param name="node">The node.</param>
		/// <param name="action">The action.</param>
		/// <param name="stateImageIndex">Index of the state image.</param>
		/// <param name="raiseEvents">if set to <c>true</c> [raise events].</param>
		private void SetTriStateToNode(
			TreeNode node,
			TreeViewAction action,
			int stateImageIndex,
			bool raiseEvents )
		{
			bool canSet = true;

			if ( raiseEvents )
			{
				TreeViewCancelEventArgs args =
					new TreeViewCancelEventArgs( node, false, action );

				OnBeforeCheck( args );

				TreeViewCancelTriStateEventArgs triArgs =
					new TreeViewCancelTriStateEventArgs(
					node,
					args.Cancel,
					action,
					node.StateImageIndex,
					stateImageIndex );

				OnBeforeTriStateCheck( triArgs );

				canSet = !triArgs.Cancel;
			}

			if ( canSet )
			{
				// Actually set.
				// THIS IS THE ONLY PLACE to set.
				node.StateImageIndex = stateImageIndex;

				if ( raiseEvents )
				{
					TreeViewEventArgs args =
						new TreeViewEventArgs( node, action );

					OnAfterCheck( args );

					TreeViewTriStateEventArgs triArgs =
						new TreeViewTriStateEventArgs(
						node,
						action,
						node.StateImageIndex );

					OnAfterTriStateCheck( triArgs );
				}
			}
		}
		/// <summary>
		/// Toggles the tri state check.
		/// </summary>
		/// <param name="node">The node.</param>
		/// <param name="action">The action.</param>
		private void ToggleTriStateCheck(
			TreeNode node,
			TreeViewAction action )
		{
			if ( node.StateImageIndex == TriStateUncheckedStateImageIndex )
			{
				SetTriStateToNode(
				node,
				action,
				TriStateCheckedStateImageIndex,
				true );
			}
			else if ( node.StateImageIndex == TriStateIndeterminateStateImageIndex &&
				indeterminateToChecked )
			{
				SetTriStateToNode(
				node,
				action,
				TriStateCheckedStateImageIndex,
				true );
			}
			else
			{
				SetTriStateToNode(
				node,
				action,
				TriStateUncheckedStateImageIndex,
				true );
			}
		}
		/// <summary>
		/// Applies a new check state to the given tree node.
		/// The UseTriStateCheckBoxes property must be set to TRUE.
		/// </summary>
		/// <param name="node">The node.</param>
		/// <param name="action">The action.</param>
		/// <param name="checkState">State of the check.</param>
		private void DoSetNodeCheckState(
			TreeNode node,
			TreeViewAction action,
			CheckState checkState )
		{
			// Use TreeViewAction.ByKeyboard here, 
			// to indicate that it was called from outside.
			SetTriStateToNode(
				node,
				action,
				ConvertCheckStateToImageIndex( checkState ),
				true );
		}
			/// <summary>
			/// Initializes a new instance of the <see cref="TreeViewTriStateEventArgs"/> class.
			/// </summary>
			/// <param name="node">The node.</param>
			/// <param name="action">The action.</param>
			/// <param name="stateImageIndex">Index of the state image.</param>
			public TreeViewTriStateEventArgs(
				TreeNode node,
				TreeViewAction action,
				int stateImageIndex )
				:
				base( node, action )
			{
				this.stateImageIndex = stateImageIndex;
			}
			/// <summary>
			/// Constructor.
			/// </summary>
			/// <param name="node">The node.</param>
			/// <param name="cancel">if set to <c>true</c> [cancel].</param>
			/// <param name="action">The action.</param>
			/// <param name="currentStateImageIndex">Index of the current state image.</param>
			/// <param name="newStateImageIndex">New index of the state image.</param>
			public TreeViewCancelTriStateEventArgs(
					TreeNode node,
					bool cancel,
					TreeViewAction action,
					int currentStateImageIndex,
					int newStateImageIndex )
				:
				base( node, cancel, action )
			{
				this.currentStateImageIndex = currentStateImageIndex;
				this.newStateImageIndex = newStateImageIndex;
			}
 public TreeViewEventArgs(TreeNode node, TreeViewAction action)
 {
 }
Ejemplo n.º 17
0
 public MultiSelectTreeViewCancelEventArgs(MultiSelectTreeNode node, bool cancel, TreeViewAction action)
     : base(cancel)
 {
     _node = node;
     _action = action;
 }
        /// <summary>
        /// Selects nodes within the specified range.
        /// </summary>
        /// <param name="startNode">Start node.</param>
        /// <param name="endNode">End Node.</param>
        /// <param name="tva">Specifies the action that caused the selection change.</param>
        private void SelectNodesInsideRange(TreeNode startNode, TreeNode endNode, TreeViewAction tva)
        {
            // Calculate start node and end node
            TreeNode firstNode = null;
            TreeNode lastNode = null;

            SortNodes(ref startNode, ref endNode);

            firstNode = startNode;
            lastNode = endNode;

            //This was a terrible idea, whoever came up with it...
            // Bounds are not updated always and it's not fixable as it's part of .NET framework.
            // Much better is to rely on a real index in a tree model
            /*

            if (startNode.Bounds.Y < endNode.Bounds.Y)
            {
                firstNode = startNode;
                lastNode = endNode;
            }
            else
            {
                firstNode = endNode;
                lastNode = startNode;
            }
            */

            // Select each node in range

            SelectNode(firstNode, true, tva);
            TreeNode tnTemp = firstNode;
            while (tnTemp != lastNode)
            {
                tnTemp = tnTemp.NextVisibleNode;
                if (tnTemp != null)
                {
                    SelectNode(tnTemp, true, tva);
                }
            }
            SelectNode(lastNode, true, tva);
        }
Ejemplo n.º 19
0
		/// <summary>
		/// Unselects all selected nodes.
		/// </summary>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void UnselectAllNodes(TreeViewAction tva)
		{
			UnselectAllNodesExceptNode(null, tva);
		}
Ejemplo n.º 20
0
        private static void ModifyFolderExpandedState(TreeNode Node, TreeViewAction Action)
        {
            ConfigItems.NodeDescription nodeDescr = (ConfigItems.NodeDescription)Node.Tag;

            switch (nodeDescr.TreeNodeType)
            {
                case NodeType.Folder:
                    ConfigItems.TDSQueriesTree.FoldersRow folder = (ConfigItems.TDSQueriesTree.FoldersRow)nodeDescr.NodeData;

                    folder.Expanded = (Action == TreeViewAction.Expand ? true : false);

                    break;
            }
        }
Ejemplo n.º 21
0
		/// <summary>
		/// Unselects all selected nodes that don't belong directly or indirectly to the specified parent.
		/// </summary>
		/// <param name="parent">Parent node.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void UnselectAllNodesNotBelongingToParent(TreeNode parent, TreeViewAction tva)
		{
			// First, build list of nodes that need to be unselected
			ArrayList arrNodesToDeselect = new ArrayList();
			foreach (TreeNode selectedTreeNode in htblSelectedNodes.Values)
			{
				if (!IsChildOf(selectedTreeNode, parent))
				{
					arrNodesToDeselect.Add(selectedTreeNode);
				}
			}

			// Do the actual unselect
			foreach (TreeNode tnToDeselect in arrNodesToDeselect)
			{
				SelectNode(tnToDeselect, false, tva);
			}
		}
Ejemplo n.º 22
0
 private void ChangeNodeStateByUser(TreeNode node, TreeViewAction action)
 {
     if (this.BeforeNodeStateChangeByUser != null)
     {
         this.BeforeNodeStateChangeByUser(this, new TreeViewEventArgs(node, action));
     }
     switch (node.StateImageIndex)
     {
         case ItemState.Unchecked:
         case ItemState.Mixed:
             node.StateImageIndex = ItemState.Checked;
             break;
         case ItemState.Checked:
             node.StateImageIndex = ItemState.Unchecked;
             break;
     }
     UpdateChildren(node);
     UpdateParent(node);
 }
Ejemplo n.º 23
0
		/// <summary>
		/// (Un)selects the specified node.
		/// </summary>
		/// <param name="tn">Node to (un)select.</param>
		/// <param name="select">True to select node, false to unselect node.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		/// <returns>True if node was selected, false if not.</returns>
		private bool SelectNode(TreeNode tn, bool select, TreeViewAction tva)
		{
			bool blnSelected = false;

			if (tn == null)
				return false;

			if (select)
			{
				// Only try to select node if it was not already selected																		
				if (!IsNodeSelected(tn))
				{
					// Check if node selection is cancelled
					TreeViewCancelEventArgs tvcea = new TreeViewCancelEventArgs(tn, false, tva);
					base.OnBeforeSelect(tvcea);
					if (tvcea.Cancel)
					{
						// This node selection was cancelled!						
						return false;
					}

					PreserveNodeColors(tn);

					tn.BackColor = SelectionBackColor; // GKM moved from above
					tn.ForeColor = BackColor; // GKM moved from above									

					htblSelectedNodes.Add(tn.GetHashCode(), tn);
					blnSelected = true;
					blnSelectionChanged = true;

					base.OnAfterSelect(new TreeViewEventArgs(tn, tva));
				}

				tnMostRecentSelectedNode = tn;
			}
			else
			{
				// Only unselect node if it was selected
				if (IsNodeSelected(tn))
				{
					OnBeforeDeselect(tn);

					Color[] originalColors = (Color[])this.htblSelectedNodesOrigColors[tn.GetHashCode()];
					if (originalColors != null)
					{
						htblSelectedNodes.Remove(tn.GetHashCode());
						blnSelectionChanged = true;
						htblSelectedNodesOrigColors.Remove(tn.GetHashCode());

						// GKM - Restore original node colors
						tn.BackColor = originalColors[0]; // GKM - was BackColor;
						tn.ForeColor = originalColors[1]; // GKM - was ForeColor;
					}

					OnAfterDeselect(tn);
				}
			}

			return blnSelected;
		}
 public TreeViewEventArgs(TreeNode node, TreeViewAction action)
 {
     this.node = node;
     this.action = action;
 }
Ejemplo n.º 25
0
		/// <summary>
		/// Unselects nodes outside the specified range.
		/// </summary>
		/// <param name="startNode">Start node.</param>
		/// <param name="endNode">End node.</param>
		/// <param name="tva">Specifies the action that caused the selection change.</param>
		private void UnselectNodesOutsideRange(TreeNode startNode, TreeNode endNode, TreeViewAction tva)
		{
			// Calculate start node and end node
			TreeNode firstNode = null;
			TreeNode lastNode = null;
			if (startNode.Bounds.Y < endNode.Bounds.Y)
			{
				firstNode = startNode;
				lastNode = endNode;
			}
			else
			{
				firstNode = endNode;
				lastNode = startNode;
			}

			// Unselect each node outside range
			TreeNode tnTemp = firstNode;
			while (tnTemp != null)
			{
				tnTemp = tnTemp.PrevVisibleNode;
				if (tnTemp != null)
				{
					SelectNode(tnTemp, false, tva);
				}
			}

			tnTemp = lastNode;
			while (tnTemp != null)
			{
				tnTemp = tnTemp.NextVisibleNode;
				if (tnTemp != null)
				{
					SelectNode(tnTemp, false, tva);
				}
			}
		}
Ejemplo n.º 26
0
        /// <include file='doc\TreeView.uex' path='docs/doc[@for="TreeView.TreeViewBeforeAfterCheck"]/*' />
        /// <devdoc>
        ///     Defined so that a  tree node can use it
        ///
        /// </devdoc>
        /// <internalonly/>

        internal bool TreeViewBeforeCheck(TreeNode node, TreeViewAction actionTaken) {
            TreeViewCancelEventArgs tvce = new TreeViewCancelEventArgs(node, false, actionTaken);
            OnBeforeCheck(tvce);
            return (tvce.Cancel);
        }
Ejemplo n.º 27
0
 public TreeViewSelectedNodeChangedArgs(TreeNode beforeNode, TreeNode afterNode, TreeViewAction action)
 {
     BeforeNode = beforeNode;
     AfterNode = afterNode;
     Action = action;
 }
Ejemplo n.º 28
0
 internal void TreeViewAfterCheck(TreeNode node, TreeViewAction actionTaken) {
     OnAfterCheck(new TreeViewEventArgs(node, actionTaken));
 }
Ejemplo n.º 29
0
		protected override void OnKeyDown (KeyEventArgs e)
		{
			OpenTreeNodeEnumerator ne;

			switch (e.KeyData & Keys.KeyCode) {
			case Keys.Add:
				if (selected_node != null && selected_node.IsExpanded)
					selected_node.Expand ();
				break;
			case Keys.Subtract:
				if (selected_node != null && selected_node.IsExpanded)
					selected_node.Collapse ();
				break;
			case Keys.Left:
				if (selected_node != null) {
					if (selected_node.IsExpanded && selected_node.Nodes.Count > 0)
						selected_node.Collapse ();
					else {
						TreeNode parent = selected_node.Parent;
						if (parent != null) {
							selection_action = TreeViewAction.ByKeyboard;
							SelectedNode = parent;
						}
					}
				}
				break;
			case Keys.Right:
				if (selected_node != null) {
					if (!selected_node.IsExpanded)
						selected_node.Expand ();
					else {
						TreeNode child = selected_node.FirstNode;
						if (child != null)
							SelectedNode = child;
					}
				}
				break;
			case Keys.Up:
				if (selected_node != null) {
					ne = new OpenTreeNodeEnumerator (selected_node);
					if (ne.MovePrevious () && ne.MovePrevious ()) {
						selection_action = TreeViewAction.ByKeyboard;
						SelectedNode = ne.CurrentNode;
					}
				}
				break;
			case Keys.Down:
				if (selected_node != null) {
					ne = new OpenTreeNodeEnumerator (selected_node);
					if (ne.MoveNext () && ne.MoveNext ()) {
						selection_action = TreeViewAction.ByKeyboard;
						SelectedNode = ne.CurrentNode;
					}
				}
				break;
			case Keys.Home:
				if (root_node.Nodes.Count > 0) {
					ne = new OpenTreeNodeEnumerator (root_node.Nodes [0]);
					if (ne.MoveNext ()) {
						selection_action = TreeViewAction.ByKeyboard;
						SelectedNode = ne.CurrentNode;
					}
				}
				break;
			case Keys.End:
				if (root_node.Nodes.Count > 0) {
					ne = new OpenTreeNodeEnumerator (root_node.Nodes [0]);
					while (ne.MoveNext ())
					{ }
					selection_action = TreeViewAction.ByKeyboard;
					SelectedNode = ne.CurrentNode;
				}
				break;
			case Keys.PageDown:
				if (selected_node != null) {
					ne = new OpenTreeNodeEnumerator (selected_node);
					int move = VisibleCount;
					for (int i = 0; i < move && ne.MoveNext (); i++) {
						
					}
					selection_action = TreeViewAction.ByKeyboard;
					SelectedNode = ne.CurrentNode;
				}
				break;
			case Keys.PageUp:
				if (selected_node != null) {
					ne = new OpenTreeNodeEnumerator (selected_node);
					int move = VisibleCount;
					for (int i = 0; i < move && ne.MovePrevious (); i++)
					{ }
					selection_action = TreeViewAction.ByKeyboard;
					SelectedNode = ne.CurrentNode;
				}
				break;
			case Keys.Multiply:
				if (selected_node != null)
					selected_node.ExpandAll ();
				break;
			}
			base.OnKeyDown (e);

			if (!e.Handled && checkboxes &&
           		     selected_node != null &&
			    (e.KeyData & Keys.KeyCode) == Keys.Space) {
				selected_node.check_reason = TreeViewAction.ByKeyboard;
				selected_node.Checked = !selected_node.Checked;		
				e.Handled = true;
			}
		}
Ejemplo n.º 30
0
 public VirtualTreeViewEventArgs(VirtualTreeNode node, TreeViewAction action)
     : this(node)
 {
     _action = action;
 }