private void DropDownToggle() { if (DroppedDown) //DroppedDown, so we need to collapse. { butDrop.ImageIndex = 0; //Set to arrow down image. _popup.Close(); //This collapses the popup. The popup is NOT disposed. FillText(); if (SelectionChangeCommitted != null) { SelectionChangeCommitted(this, new EventArgs()); } } else //Not DroppedDown, so we need to DropDown. { butDrop.ImageIndex = 1; //Set to arrow up image. #region Popup setup _popup = new PopupWindow(gridMain); _popup.AutoClose = false; //This prevents the Alt key from collapsing the combobox and prevents other events from collapsing as well. _popup.Closed += PopupWindow_Closed; _popup.Opened += PopupWindow_Opened; Control parent = Parent; int x = this.Location.X; int y = this.Location.Y; while (parent != null && !typeof(Form).IsAssignableFrom(parent.GetType())) { x += parent.Location.X; y += parent.Location.Y; parent = parent.Parent; } #endregion Popup setup _popup.Show(ParentForm, new Point(x, y + this.Height)); } //The keyboard listener lifetime begins on first dropdown and ends when the control is disposed or parent form is closed. if (_threadCheckKeyboard == null) { //When DroppedDown, will update input flags for auto collapsing. _threadCheckKeyboard = new ODThread(100, WorkerThread_KeyboardListener); _threadCheckKeyboard.Start(); } }
private void DropDownToggle() { if (DroppedDown) //DroppedDown, so we need to collapse. { if (_doUsePopup) { _popup.Close(); //This collapses the popup. The popup is NOT disposed. } else { gridMain.Visible = false; } FillText(); if (SelectionChangeCommitted != null) { SelectionChangeCommitted(this, new EventArgs()); } } else //Not DroppedDown, so we need to DropDown. { #region Popup setup //If the grid rows differ from the items count, refill the grid because something happened to the ArrayList that the control wasn't aware of. //For example, If a ComboBoxMulti never sets an item selected, the grid is never filled, even though the ArrayList has items in it. //Filling the grid when opening the dropdown matches the UI behavior found in regular combo boxes. SynchronizeGrid(); Control parent = Parent; int x = this.Location.X; int y = this.Location.Y; while (parent != null && !typeof(Form).IsAssignableFrom(parent.GetType())) { x += parent.Location.X; y += parent.Location.Y; parent = parent.Parent; } if (_doUsePopup) { _popup = new PopupWindow(gridMain); _popup.AutoClose = false; //This prevents the Alt key from collapsing the combobox and prevents other events from collapsing as well. _popup.Closed += PopupWindow_Closed; _popup.Opened += PopupWindow_Opened; #endregion Popup setup _popup.Show(ParentForm, new Point(x, y + this.Height)); } else { int gridTop = y + this.Height; if (gridTop + gridMain.Height >= ParentForm.ClientSize.Height) { //The grid does not have enough room to fit on the form. if (y > ParentForm.ClientSize.Height - gridTop) { //If there's more room, put the grid above the combobox. gridTop = y - gridMain.Height; if (gridTop < 0) { //Not enough room, shrink the grid height. gridMain.Height = y; gridTop = 0; } } else { //If there's not enough room to show the grid below, shrink the grid height. gridMain.Height = ParentForm.ClientSize.Height - gridTop; } } gridMain.Location = new Point(x, gridTop); gridMain.Anchor = this.Anchor; ParentForm.Controls.Add(gridMain); gridMain.Visible = true; gridMain.BringToFront(); } } //The keyboard listener lifetime begins on first dropdown and ends when the control is disposed or parent form is closed. if (_threadCheckKeyboard == null) { //When DroppedDown, will update input flags for auto collapsing. _threadCheckKeyboard = new ODThread(100, WorkerThread_KeyboardListener); _threadCheckKeyboard.AddExceptionHandler((ex) => ex.DoNothing()); _threadCheckKeyboard.Start(); } }