/// <summary> /// Displays the drop-down filter list. /// </summary> override public void ShowColumnFilter() { if (filterControlShowing) { HideFilterControl(); return; } Debug.Assert(this.DataGridView != null, "DataGridView is null"); // Ensure that the current row is not the row for new records. // This prevents the new row from affecting the filter list and also // prevents the new row from being added when the filter changes. if (this.DataGridView.CurrentRow != null && this.DataGridView.CurrentRow.IsNewRow) { this.DataGridView.CurrentCell = null; } if (filterWindow != null) { this.DataGridView.Controls.Remove(filterWindow); filterWindow.Dispose(); } filterWindow = new SingleSelectHeaderList(); // Populate the filters dictionary, then copy the filter values // from the filters.Keys collection into the ListBox.Items collection, // selecting the current filter if there is one in effect. PopulateFilters(); String[] filterArray = new String[filters.Count]; filters.Keys.CopyTo(filterArray, 0); filterWindow.FilterListBox.Items.Clear(); filterWindow.FilterListBox.Items.AddRange(filterArray); filterWindow.FilterListBox.SelectedItem = selectedFilterValue; // Add handlers to dropDownListBox.FilterListBox events. HandleDropDownListBoxEvents(); //textSelectBox.Visible = true; filterControlShowing = true; filterWindow.Show(this.DataGridView); // Set the size and location of dropDownListBox, then display it. SetDropDownListBoxBounds(); // Invalidate the cell so that the drop-down button will repaint // in the pressed state. this.DataGridView.InvalidateCell(this); }
/// <summary> /// Hides the drop-down filter list. /// </summary> override protected void HideFilterControl() { if (filterControlShowing) { filterControlShowing = false; Debug.Assert(this.DataGridView != null, "DataGridView is null"); // Hide dropDownListBox, remove handlers from its events, and remove // it from the DataGridView control. UnhandleDropDownListBoxEvents(); filterWindow.Visible = false; filterWindow.Dispose(); filterWindow = null; // Invalidate the cell so that the drop-down button will repaint // in the unpressed state. this.DataGridView.InvalidateCell(this); this.DataGridView.Focus(); } }