abrusko
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_ColumnHeader MouseClick (object sender, DataGridViewCellMouseEvent Args e)
{
//instantiate DataGridViewAutoFilterColu mnHeaderCe ll
DataGridViewColumn dc = dataGridView1.Columns[e.Co lumnIndex] ;
dc.HeaderCell = new DataGridViewAutoFilterColu mnHeaderCe ll(dc.Head erCell);
//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.Conta ins(
e.X + cellBounds.Left - scrollingOffset, e.Y + cellBounds.Top))
{
// If the current cell is in edit mode, commit the edit.
if (this.DataGridView.IsCurre ntCellInEd itMode)
{
// Commit and end the cell edit.
this.DataGridView.EndEdit( );
// Commit any change to the underlying data source.
BindingSource source =
this.DataGridView.DataSour ce as BindingSource;
if (source != null)
{
source.EndEdit();
}
}
ShowDropDownList();
}
private void dataGridView1_ColumnHeader
{
//instantiate DataGridViewAutoFilterColu
DataGridViewColumn dc = dataGridView1.Columns[e.Co
dc.HeaderCell = new DataGridViewAutoFilterColu
//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.Conta
e.X + cellBounds.Left - scrollingOffset, e.Y + cellBounds.Top))
{
// If the current cell is in edit mode, commit the edit.
if (this.DataGridView.IsCurre
{
// Commit and end the cell edit.
this.DataGridView.EndEdit(
// Commit any change to the underlying data source.
BindingSource source =
this.DataGridView.DataSour
if (source != null)
{
source.EndEdit();
}
}
ShowDropDownList();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
Below is Advanced DataGridView with Sorting and Filtering like excel.
http://adgv.codeplex.com/