/// <summary> /// Displays the drop-down filter list. /// </summary> public void ShowDropDownList() { try { if(dropDownListBoxShowing) { HideDropDownList(); 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; } // 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); if(selectedFilterValue.Count == 0) selectedFilterValue.AddRange(filterArray); multiSelectBox = new MultiSelectHeaderList(); multiSelectBox.FilterListBox.Items.Clear(); multiSelectBox.FilterListBox.Items.AddRange(filterArray); multiSelectBox.SelectedValues = selectedFilterValue; multiSelectBox.Parent = this.DataGridView; // Add handlers to dropDownListBox.FilterListBox events. HandleDropDownListBoxEvents(); // Set the size and location of dropDownListBox.FilterListBox, then display it. SetDropDownListBoxBounds(); //multiSelectBox.Visible = true; //multiSelectBox.Show(); dropDownListBoxShowing = true; // Set the input focus to dropDownListBox.FilterListBox. multiSelectBox.FilterListBox.Focus(); // Invalidate the cell so that the drop-down button will repaint // in the pressed state. this.DataGridView.InvalidateCell(this); } catch (Exception ex) { CErr.processError(ex, "Error while showing the column filter setting (" + this.OwningColumn.Name + ")"); } }
/// <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.FilterListBox, remove handlers from its events, and remove // it from the DataGridView control. UnhandleDropDownListBoxEvents(); filterWindow.Visible = false; filterWindow.Dispose(); filterWindow = null; //this.DataGridView.Controls.Remove(multiSelectBox); // Invalidate the cell so that the drop-down button will repaint // in the unpressed state. this.DataGridView.InvalidateCell(this); this.DataGridView.Focus(); } }
private void button1_Click(object sender, EventArgs e) { if(ml != null) ml.Dispose(); ml = new MultiSelectHeaderList(); ml.Parent = this.dgvCommandersLog; ml.Location = new Point(10,10); }
/// <summary> /// Displays the drop-down filter list. /// </summary> override public void ShowColumnFilter() { try { 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; } // 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); if (filterArray.GetUpperBound(0) == -1) { return; } if (selectedFilterValue.Count == 0) { selectedFilterValue.AddRange(filterArray); } filterWindow = new MultiSelectHeaderList(); filterWindow.FilterListBox.Items.Clear(); filterWindow.FilterListBox.Items.AddRange(filterArray); filterWindow.SelectedValues = 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); } catch (Exception ex) { CErr.processError(ex, "Error while showing the column filter setting (" + this.OwningColumn.Name + ")"); } }
/// <summary> /// Hides the drop-down filter list. /// </summary> public void HideDropDownList() { Debug.Assert(this.DataGridView != null, "DataGridView is null"); // Hide dropDownListBox.FilterListBox, remove handlers from its events, and remove // it from the DataGridView control. UnhandleDropDownListBoxEvents(); dropDownListBoxShowing = false; multiSelectBox.Visible = false; multiSelectBox.Dispose(); multiSelectBox = null; //this.DataGridView.Controls.Remove(multiSelectBox); // Invalidate the cell so that the drop-down button will repaint // in the unpressed state. this.DataGridView.InvalidateCell(this); }