diff --git a/PROMS/VEPROMS User Interface/frmVEPROMS.cs b/PROMS/VEPROMS User Interface/frmVEPROMS.cs index fa776abe..471c2f27 100644 --- a/PROMS/VEPROMS User Interface/frmVEPROMS.cs +++ b/PROMS/VEPROMS User Interface/frmVEPROMS.cs @@ -264,15 +264,41 @@ namespace VEPROMS /// /// When the treeview is clicked - a timer is set /// This is done because the focus is returned to the treeview after the click event + /// This approach did not work and was replaced with the code below. + /// The problem was that each time the treeview was clicked, the last selected node + /// was opened again, or the edit window was repositioned. + /// If the item was deleted and another treenode expanded, the click to expand the + /// node would cause the deleted node to be selected. /// /// /// - private void tv_Click(object sender, EventArgs e) + //private void tv_Click(object sender, EventArgs e) + //{ + //tv.Enabled = false; + //tmrTreeView.Enabled = true; + //} + /// + /// This opens nodes if the mouse is within the bounds of a node. + /// By using the timer, the focus can be passed to the edit window. + /// + /// + /// + void tv_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { - tv.Enabled = false; - tmrTreeView.Enabled = true; + if (e.Button != MouseButtons.Right) + { + Point newPoint = new Point(e.X, e.Y); + VETreeNode tn = tv.GetNodeAt(newPoint) as VETreeNode; + // Check to make sure that a node has been selected and + // that the mouse is within the bounds of the node. + if (tn != null && tn.Bounds.Left < newPoint.X) + { + tv.SelectedNode = tn; + tv.Enabled = false; + tmrTreeView.Enabled = true; + } + } } - /// /// This event is fired from the timer after the treeview click event completes ///