Example #1
0
 /// <summary>
 /// Displays the specified control in a drop down area below a value field of the property grid that provides this service.
 /// </summary>
 /// <param name="control">The drop down list <see cref="T:System.Windows.Forms.Control"></see> to open.</param>
 public virtual void DropDownControl(System.Windows.Forms.Control control)
 {
     this.dropDown = new DropDownCustom(this, control);
     this.dropDown.DropDownBehaviours = DropDownBehaviours.CloseOnEscape;
     this.dropDown.ShowDropDown();
     this.dropDown = null;
 }
        /// <summary>
        /// Populate and show the listbox
        /// </summary>
        public virtual void ShowListBox()
        {
            OnDropDownOpen(EventArgs.Empty);

            using (ListBox l_ListBox = new ListBox())
            {
                l_ListBox.BorderStyle         = BorderStyle.None;
                l_ListBox.HorizontalScrollbar = true;
                l_ListBox.IntegralHeight      = false;
                if (Validator.StandardValues != null)
                {
                    foreach (object o in Validator.StandardValues)
                    {
                        l_ListBox.Items.Add(Validator.ValueToDisplayString(o));
                    }
                }

                // Calculate the height of the ListBox : l_ListBox.Height
                int defaultHeight = l_ListBox.ItemHeight * 3;
                int maximumHeight = (int)(Screen.PrimaryScreen.Bounds.Height / 2.1);
                l_ListBox.Height = Math.Max(defaultHeight, Math.Min(maximumHeight, l_ListBox.PreferredHeight)) + 2;

                using (DropDownCustom l_DropDown = new DropDownCustom(this, l_ListBox))
                {
                    if (selectedItem >= 0 && selectedItem < l_ListBox.Items.Count)
                    {
                        l_ListBox.SelectedIndex = selectedItem;
                    }
                    l_ListBox.SelectedIndexChanged += new EventHandler(ListBox_SelectedChange);
                    l_ListBox.Click += new EventHandler(ListBox_Click);
                    l_DropDown.ShowDropDown();
                    l_ListBox.Click -= new EventHandler(ListBox_Click);
                    l_ListBox.SelectedIndexChanged -= new EventHandler(ListBox_SelectedChange);

                    txtBox.Focus();

                    OnDropDownClosed(EventArgs.Empty);
                }
            }
        }