/// <summary> /// Raises the <see cref="E:System.Windows.Forms.TreeView.AfterLabelEdit"/> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.NodeLabelEditEventArgs"/> that contains the event data.</param> protected override void OnAfterLabelEdit(NodeLabelEditEventArgs e) { base.LabelEdit = false; e.CancelEdit = string.IsNullOrEmpty(e.Label); if (!e.CancelEdit) { TreeNodeEx node = e.Node as TreeNodeEx; if (node != null) { node.OnAfterLabelEdit(e.Label); } SortParent(e.Node); RefreshParent(e.Node); // I don't know why we need this last instruction, // but if we don"t apply a refresh, display bugs appear. // For example, when renaming a node, the first node is // displayed with the other node's new label. } //e.CancelEdit = true; editingLabel = false; // We also need this, because RefreshParent (or SortParent?) loses the currently selected node: // The selected node isn't changed, but it displays the root node as selected base.SelectedNode = e.Node; base.OnAfterLabelEdit(e); }
/// <summary>Called when after a node has been activated.</summary> /// <param name="node">The node.</param> protected virtual void OnAfterActivateNode(TreeNodeEx node) { if (NodeActivated != null) { NodeActivated(this, new TreeNodeExEventArgs(node)); } }
/// <summary> /// Activates the currently selected node. /// </summary> private void ActivateSelectedNode() { TreeNodeEx node = base.SelectedNode as TreeNodeEx; if (node != null) { ActivateNode(node); } }
public virtual ContextMenuStrip GetContextMenuStrip(TreeNodeEx node) { // Example //ContextMenuStrip strip = new ContextMenuStrip(); //strip.Items.Add("Menu 1"); //strip.Items.Add("Menu 2"); //return strip; return(null); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.TreeView.AfterSelect"/> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.TreeViewEventArgs"/> that contains the event data.</param> protected override void OnAfterSelect(TreeViewEventArgs e) { base.OnAfterSelect(e); TreeNodeEx selectedNode = e.Node as TreeNodeEx; if ((selectedNode != null) && (SelectedNodeChanged != null) /*&& (selectedNode != base.SelectedNode)*/) { SelectedNodeChanged(this, new TreeNodeExEventArgs(selectedNode)); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.TreeView.BeforeExpand"/> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.TreeViewCancelEventArgs"/> that contains the event data.</param> protected override void OnBeforeExpand(TreeViewCancelEventArgs e) { expanding = true; mouseDownSelectedNode = null; TreeNodeEx node = e.Node as TreeNodeEx; if (node != null) { node.Expanding(e); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.TreeView.BeforeCollapse"/> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.TreeViewCancelEventArgs"/> that contains the event data.</param> protected override void OnBeforeCollapse(TreeViewCancelEventArgs e) { collapsing = true; mouseDownSelectedNode = null; TreeNodeEx node = e.Node as TreeNodeEx; if (node != null) { node.Collapsing(e); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.TreeView.BeforeLabelEdit"/> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.NodeLabelEditEventArgs"/> that contains the event data.</param> protected override void OnBeforeLabelEdit(NodeLabelEditEventArgs e) { editingLabel = true; e.Node.EnsureVisible(); TreeNodeEx node = e.Node as TreeNodeEx; if (node != null) { node.OnBeforeLabelEdit(); } base.OnBeforeLabelEdit(e); }
/// <summary>Begins the label edition.</summary> /// <param name="node">The node.</param> /// <param name="forceEdit">if set to <c>true</c>, force the edition.</param> public void BeginLabelEdit(TreeNodeEx node, bool forceEdit) { if (LabelEdit && (node != null) && (node.LabelEdit)) { if (base.SelectedNode != node) { base.SelectedNode = node; } base.LabelEdit = true; if (forceEdit) { node.BeginEdit(); } } }
protected virtual int DoCompare(TreeNode x, TreeNode y) { Debug.Assert(x != null); Debug.Assert(y != null); TreeNodeEx node1 = x as TreeNodeEx; TreeNodeEx node2 = y as TreeNodeEx; if (node1 == null || node2 == null) { return(x.Text.CompareTo(y.Text)); } return(node1.CompareTo(node2)); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.DragDrop"/> event. /// </summary> /// <param name="drgevent">A <see cref="T:System.Windows.Forms.DragEventArgs"/> that contains the event data.</param> protected override void OnDragDrop(DragEventArgs drgevent) { base.OnDragDrop(drgevent); if (!allowDrag) { return; } Point pt = base.PointToClient(new Point(drgevent.X, drgevent.Y)); TreeNodeEx node = base.GetNodeAt(pt) as TreeNodeEx; if (node != null) { node.DoDragDrop(drgevent); SortParent(node); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.TreeView.ItemDrag"/> event. /// </summary> /// <param name="e">An <see cref="T:System.Windows.Forms.ItemDragEventArgs"/> that contains the event data.</param> protected override void OnItemDrag(ItemDragEventArgs e) { base.OnItemDrag(e); if (!allowDrag) { return; } TreeNodeEx node = e.Item as TreeNodeEx; if (node != null) { DataObject data = node.GetDataObject(); if (data != null) { base.DoDragDrop(data, DragDropEffects.All); SortParent(node); } } }
/// <summary>Activates the specified node.</summary> /// <param name="node">The node to activate.</param> public void ActivateNode(TreeNodeEx node) { if (node == null) { throw new ArgumentNullException("node"); } if (node.TreeView != this) { throw new ArgumentException("This node doesn't belong to this treeview", "node"); } OnBeforeActivateNode(node); CancelEventArgs e = new CancelEventArgs(false); node.ActivateInternal(e); if (!e.Cancel) { OnAfterActivateNode(node); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.DragOver"/> event. /// </summary> /// <param name="drgevent">A <see cref="T:System.Windows.Forms.DragEventArgs"/> that contains the event data.</param> protected override void OnDragOver(DragEventArgs drgevent) { base.OnDragOver(drgevent); if (!allowDrag) { return; } Point pt = base.PointToClient(new Point(drgevent.X, drgevent.Y)); TreeNodeEx node = base.GetNodeAt(pt) as TreeNodeEx; if (node != null) { DragDropEffects effect = DragDropEffects.None; if ((drgevent.KeyState & CTRL_KEYSTATE) == CTRL_KEYSTATE) { effect = DragDropEffects.Copy; } else { effect = DragDropEffects.Move; } drgevent.Effect = node.FilterEffect(effect); if (drgevent.Effect != DragDropEffects.None) { if ((lastDragOverNode != null) && (lastDragOverNode != node)) { lastDragOverNode.DoDragLeave(drgevent); } node.DoDragOver(drgevent); base.SelectedNode = lastDragOverNode = node; } } }
/// <summary>Called before activating a node.</summary> /// <param name="node">The node.</param> protected virtual void OnBeforeActivateNode(TreeNodeEx node) { }
public TreeNodeExEventArgs(TreeNodeEx bstn) : base() { node = bstn; }
/// <summary>Begins the label edition.</summary> /// <param name="node">The node.</param> public void BeginLabelEdit(TreeNodeEx node) { BeginLabelEdit(node, true); }