/// <summary> /// Method to hide the currently-selected node's ComboBox /// </summary> private void HideComboBox() { if (m_CurrentOFDropDownNode != null) { ComboBox_ChangeValue(); m_ChangeValue = false; // Unregister the event listener m_CurrentOFDropDownNode.ComboBox.SelectedValueChanged -= ComboBox_SelectedValueChanged; m_CurrentOFDropDownNode.ComboBox.DropDownClosed -= ComboBox_DropDownClosed; // Copy the selected text from the ComboBox to the TreeNode m_CurrentOFDropDownNode.Text = m_CurrentOFDropDownNode.ComboBox.Text; // Hide the ComboBox m_CurrentOFDropDownNode.ComboBox.Hide(); m_CurrentOFDropDownNode.ComboBox.DroppedDown = false; // Remove the control from the TreeView's list of currently-displayed controls Controls.Remove(m_CurrentOFDropDownNode.ComboBox); // And return to the default state (no ComboBox displayed) m_CurrentOFDropDownNode = null; } }
/// <summary> /// Occurs when the <see cref="E:System.Windows.Forms.TreeView.NodeMouseClick"></see> event is fired /// -- that is, when a node in the tree view is clicked. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.TreeNodeMouseClickEventArgs"></see> that contains the event data.</param> protected override void OnNodeMouseClick(TreeNodeMouseClickEventArgs e) { // Are we dealing with a dropdown node? if (e.Node is OpenFOAMDropDownTreeNode <dynamic> ) { m_CurrentOFDropDownNode = (OpenFOAMDropDownTreeNode <dynamic>)e.Node; // Need to add the node's ComboBox to the TreeView's list of controls for it to work Controls.Add(m_CurrentOFDropDownNode.ComboBox); // Set the bounds of the ComboBox, with a little adjustment to make it look right m_CurrentOFDropDownNode.ComboBox.SetBounds( m_CurrentOFDropDownNode.Bounds.X - 1, m_CurrentOFDropDownNode.Bounds.Y - 2, m_CurrentOFDropDownNode.Bounds.Width + 25, m_CurrentOFDropDownNode.Bounds.Height); // Listen to the SelectedValueChanged event of the node's ComboBox m_CurrentOFDropDownNode.ComboBox.SelectedValueChanged += new EventHandler(ComboBox_SelectedValueChanged); m_CurrentOFDropDownNode.ComboBox.DropDownClosed += new EventHandler(ComboBox_DropDownClosed); // Now show the ComboBox m_CurrentOFDropDownNode.ComboBox.Show(); m_CurrentOFDropDownNode.ComboBox.DroppedDown = true; } else if (e.Node is OpenFOAMTextBoxTreeNode <dynamic> ) { if (m_CurrentOFTxtBoxTreeNode != (OpenFOAMTextBoxTreeNode <dynamic>)e.Node) { HideTextBox(); } m_CurrentOFTxtBoxTreeNode = (OpenFOAMTextBoxTreeNode <dynamic>)e.Node; Controls.Add(m_CurrentOFTxtBoxTreeNode.TxtBox); //Set location of the TextBox. m_CurrentOFTxtBoxTreeNode.TxtBox.SetBounds( m_CurrentOFTxtBoxTreeNode.Bounds.X - 1, m_CurrentOFTxtBoxTreeNode.Bounds.Y - 2, m_CurrentOFTxtBoxTreeNode.Bounds.Width + 25, m_CurrentOFTxtBoxTreeNode.Bounds.Height); //Listen to Click/Leave and TextChanged Event of the TextBox. m_CurrentOFTxtBoxTreeNode.TxtBox.TextChanged += new EventHandler(TextBox_TextChanged); m_CurrentOFTxtBoxTreeNode.TxtBox.Click += new EventHandler(TextBox_Click); m_CurrentOFTxtBoxTreeNode.TxtBox.MouseLeave += new EventHandler(TextBox_Leave); m_CurrentOFTxtBoxTreeNode.TxtBox.Show(); } else { HideTextBox(); HideComboBox(); } base.OnNodeMouseClick(e); }