/// <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 DropDownTreeNode)
            {
                this.m_CurrentNode = (DropDownTreeNode)e.Node;

                // Need to add the node's ComboBox to the TreeView's list of controls for it to work
                this.Controls.Add(this.m_CurrentNode.ComboBox);

                // Set the bounds of the ComboBox, with a little adjustment to make it look right
                this.m_CurrentNode.ComboBox.SetBounds(
                    this.m_CurrentNode.Bounds.X - 1,
                    this.m_CurrentNode.Bounds.Y - 2,
                    this.m_CurrentNode.Bounds.Width + 25,
                    this.m_CurrentNode.Bounds.Height);

                // Listen to the SelectedValueChanged event of the node's ComboBox
                this.m_CurrentNode.ComboBox.SelectedValueChanged += new EventHandler(ComboBox_SelectedValueChanged);
                this.m_CurrentNode.ComboBox.DropDownClosed       += new EventHandler(ComboBox_DropDownClosed);

                // Now show the ComboBox
                this.m_CurrentNode.ComboBox.Show();
                this.m_CurrentNode.ComboBox.DroppedDown = true;
            }
            base.OnNodeMouseClick(e);
        }
        /// <summary>
        /// Method to hide the currently-selected node's ComboBox
        /// </summary>
        private void HideComboBox()
        {
            if (this.m_CurrentNode != null)
            {
                // Unregister the event listener
                this.m_CurrentNode.ComboBox.SelectedValueChanged -= ComboBox_SelectedValueChanged;
                this.m_CurrentNode.ComboBox.DropDownClosed       -= ComboBox_DropDownClosed;

                // Copy the selected text from the ComboBox to the TreeNode
                this.m_CurrentNode.Text = this.m_CurrentNode.ComboBox.Text;

                // Hide the ComboBox
                this.m_CurrentNode.ComboBox.Hide();
                this.m_CurrentNode.ComboBox.DroppedDown = false;

                // Remove the control from the TreeView's list of currently-displayed controls
                this.Controls.Remove(this.m_CurrentNode.ComboBox);

                // And return to the default state (no ComboBox displayed)
                this.m_CurrentNode = 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 DropDownTreeNode)
            {
                this.m_CurrentNode = (DropDownTreeNode)e.Node;

                // Need to add the node's ComboBox to the TreeView's list of controls for it to work
                this.Controls.Add(this.m_CurrentNode.ComboBox);

                // Set the bounds of the ComboBox, with a little adjustment to make it look right
                this.m_CurrentNode.ComboBox.SetBounds(
                    this.m_CurrentNode.Bounds.X - 1,
                    this.m_CurrentNode.Bounds.Y - 2,
                    this.m_CurrentNode.Bounds.Width + 25,
                    this.m_CurrentNode.Bounds.Height);

                // Listen to the SelectedValueChanged event of the node's ComboBox
                this.m_CurrentNode.ComboBox.SelectedValueChanged += new EventHandler(ComboBox_SelectedValueChanged);
                this.m_CurrentNode.ComboBox.DropDownClosed += new EventHandler(ComboBox_DropDownClosed);

                // Now show the ComboBox
                this.m_CurrentNode.ComboBox.Show();
                this.m_CurrentNode.ComboBox.DroppedDown = true;
            }
            base.OnNodeMouseClick(e);
        }
        /// <summary>
        /// Method to hide the currently-selected node's ComboBox
        /// </summary>
        private void HideComboBox()
        {
            if (this.m_CurrentNode != null)
            {
                // Unregister the event listener
                this.m_CurrentNode.ComboBox.SelectedValueChanged -= ComboBox_SelectedValueChanged;
                this.m_CurrentNode.ComboBox.DropDownClosed -= ComboBox_DropDownClosed;

                // Copy the selected text from the ComboBox to the TreeNode
                this.m_CurrentNode.Text = this.m_CurrentNode.ComboBox.Text;

                // Hide the ComboBox
                this.m_CurrentNode.ComboBox.Hide();
                this.m_CurrentNode.ComboBox.DroppedDown = false;

                // Remove the control from the TreeView's list of currently-displayed controls
                this.Controls.Remove(this.m_CurrentNode.ComboBox);

                // And return to the default state (no ComboBox displayed)
                this.m_CurrentNode = null;
            }
        }
Exemplo n.º 5
0
        private void InitializeExampleComponents()
        {
            DropDownTreeNode tn1 = new DropDownTreeNode("Vacation 2006 (Denver)");
            tn1.ComboBox.Items.Add("Vacation 2006 (Denver)");
            tn1.ComboBox.Items.Add("Vacation 2005 (Miami)");
            tn1.ComboBox.Items.Add("Vacation 2004 (Washington DC)");
            tn1.ComboBox.Items.Add("Vacation 2003 (Houston)");
            tn1.ComboBox.SelectedIndex = 0;
            tn1.BackColor = Color.AliceBlue;
            tn1.ComboBox.BackColor = Color.AliceBlue;

            DropDownTreeNode tn2 = new DropDownTreeNode("Vacation 2005 (Miami)");
            tn2.ComboBox.Items.Add("Vacation 2006 (Denver)");
            tn2.ComboBox.Items.Add("Vacation 2005 (Miami)");
            tn2.ComboBox.Items.Add("Vacation 2004 (Washington DC)");
            tn2.ComboBox.Items.Add("Vacation 2003 (Houston)");
            tn2.ComboBox.SelectedIndex = 1;
            tn2.BackColor = Color.Plum;
            tn2.ComboBox.BackColor = Color.Plum;

            DropDownTreeNode tn3 = new DropDownTreeNode("Vacation 2006 (Washington DC)");
            tn3.ComboBox.Items.Add("Vacation 2006 (Denver)");
            tn3.ComboBox.Items.Add("Vacation 2005 (Miami)");
            tn3.ComboBox.Items.Add("Vacation 2004 (Washington DC)");
            tn3.ComboBox.Items.Add("Vacation 2003 (Houston)");
            tn3.ComboBox.SelectedIndex = 2;
            tn3.BackColor = Color.LightSalmon;
            tn3.ComboBox.BackColor = Color.LightSalmon;

            TreeNode photoNode = new TreeNode("Photo Sets To Print");
            photoNode.Nodes.Add(tn1);
            photoNode.Nodes.Add(tn2);
            photoNode.Nodes.Add(tn3);
            this.dropDownTreeView1.Nodes.Add(photoNode);

            DropDownTreeNode pickleNode = new DropDownTreeNode("No pickles");
            pickleNode.ComboBox.Items.Add("No pickles");
            pickleNode.ComboBox.Items.Add("Add pickles");
            pickleNode.ComboBox.SelectedIndex = 0;

            DropDownTreeNode lettuceNode = new DropDownTreeNode("No lettuce");
            lettuceNode.ComboBox.Items.Add("No lettuce");
            lettuceNode.ComboBox.Items.Add("Add lettuce");
            lettuceNode.ComboBox.SelectedIndex = 0;

            DropDownTreeNode onionNode = new DropDownTreeNode("No onions");
            onionNode.ComboBox.Items.Add("No onions");
            onionNode.ComboBox.Items.Add("Add onions");
            onionNode.ComboBox.SelectedIndex = 0;

            TreeNode condimentsNode = new TreeNode("Condiments");
            condimentsNode.Nodes.Add(pickleNode);
            condimentsNode.Nodes.Add(lettuceNode);
            condimentsNode.Nodes.Add(onionNode);

            DropDownTreeNode weightNode = new DropDownTreeNode("1/4 lb.");
            weightNode.ComboBox.Items.Add("1/4 lb.");
            weightNode.ComboBox.Items.Add("1/2 lb.");
            weightNode.ComboBox.Items.Add("3/4 lb.");
            weightNode.ComboBox.SelectedIndex = 0;

            DropDownTreeNode pattyNode = new DropDownTreeNode("All beef patty");
            pattyNode.ComboBox.Items.Add("All beef patty");
            pattyNode.ComboBox.Items.Add("All chicken patty");
            pattyNode.ComboBox.SelectedIndex = 0;

            TreeNode meatNode = new TreeNode("Meat Selection");
            meatNode.Nodes.Add(weightNode);
            meatNode.Nodes.Add(pattyNode);

            TreeNode burgerNode = new TreeNode("Hamburger Selection");
            burgerNode.Nodes.Add(condimentsNode);
            burgerNode.Nodes.Add(meatNode);
            this.dropDownTreeView1.Nodes.Add(burgerNode);

            this.dropDownTreeView1.ExpandAll();
        }