Link to home
Start Free TrialLog in
Avatar of abrusko
abruskoFlag for United States of America

asked on

DataGridViewAutoFilter filter box click vs column header click

I have some code in my ColumnHeaderMouseClick event for my datagrid to sort programatically among other things.  I am using the DataGridViewAutoFilter.dll for filtering on almost all my datagrid columns, I do not want any of my code in the ColumnHeaderMouseClick to execute if the user was trying to click the little filter arrow.  Here would be the psuedo code I do not know how to write.

private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  {
   //instantiate DataGridViewAutoFilterColumnHeaderCell
   DataGridViewColumn dc = dataGridView1.Columns[e.ColumnIndex];
   dc.HeaderCell = new DataGridViewAutoFilterColumnHeaderCell(dc.HeaderCell);
  //somehow access the functions in dc, the source code for DataGridViewAutoFilter shows
  //a function that can tell if the little filter box was clicked that they call from the
  //mousdown event
  }

Here is SOME of their code in the dll
            // Show the drop-down list if filtering is enabled and the mouse click occurred
            // within the drop-down button bounds. Otherwise, if sorting is enabled and the
            // click occurred outside the drop-down button bounds, sort by the owning column.
            // The mouse coordinates are relative to the cell bounds, so the cell location
            // and the scrolling offset are needed to determine the client coordinates.
            if (FilteringEnabled &&
                DropDownButtonBounds.Contains(
                e.X + cellBounds.Left - scrollingOffset, e.Y + cellBounds.Top))
            {
                // If the current cell is in edit mode, commit the edit.
                if (this.DataGridView.IsCurrentCellInEditMode)
                {
                    // Commit and end the cell edit.  
                    this.DataGridView.EndEdit();

                    // Commit any change to the underlying data source.
                    BindingSource source =
                        this.DataGridView.DataSource as BindingSource;
                    if (source != null)
                    {
                        source.EndEdit();
                    }
                }
                ShowDropDownList();
            }
Avatar of Kalpesh Chhatrala
Kalpesh Chhatrala
Flag of India image

Hello,

Below is Advanced DataGridView with Sorting and Filtering like excel.

http://adgv.codeplex.com/
ASKER CERTIFIED SOLUTION
Avatar of abrusko
abrusko
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of abrusko

ASKER

Too bad I didn't know about that other datagrid before.  Here is what I did to fix what I had in the meantime, ugly but works.