We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do implement an Excel-like autofilter

Thread ID:

Created:

Updated:

Platform:

Replies:

23967 Jan 26,2005 08:32 AM UTC Jan 27,2005 05:18 AM UTC Windows Forms 5
loading
Tags: GridControl
Charles Vereker
Asked On January 26, 2005 08:32 AM UTC

How does one extend the filter so that it behaves like an Excel autofilter? I have tried capturing the FilterBarTextChanged event and using a code example from this forum GridCurrentCell cc = gridIDDetailsList.CurrentCell; // if in the filter row if(cc.RowIndex == 1 && cc.ColIndex > 0) { GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer; if(cr!=null) { DataTable dt = cr.ListBoxPart.DataSource as DataTable; string colName = dt.Columns[0].ColumnName; dt = new DataTable("MyFilterTable"); dt.Columns.Add(new DataColumn(colName)); dt.PrimaryKey = new DataColumn[] {dt.Columns[0]}; DataRow dr = dt.NewRow(); dr[0] = "(none)"; dt.Rows.Add(dr); dr = dt.NewRow(); dr[0] = "(custom)"; dt.Rows.Add(dr); for(int i = gridIDDetailsList.TopRowIndex; i <= gridIDDetailsList.GridCellsRange.Bottom; ++i) { dr = dt.NewRow(); dr[0] = gridIDDetailsList[i, cc.ColIndex].FormattedText; if (dt.Rows.Contains(dr[0]) == false) dt.Rows.Add(dr); } cr.ListBoxPart.DataSource = dt; } } However this only updates one column filter (it is faster than using a string builder, which was in one example)

Administrator [Syncfusion]
Replied On January 26, 2005 08:50 AM UTC

Did you see this thread? http://64.78.18.34/Support/Forums/message.aspx?MessageID=23781 It suggests using CurrentCellShowingDropDown to adjust each list as it is droped.

Charles Vereker
Replied On January 26, 2005 09:03 AM UTC

Yes. I had seen that. It seemed rather heavy to repopulate the drop down box every time it is shown, regardless of whether the filter text changes. It would be nice to be able to go theFilterBar.ReflectGridChanges = true;

Charles Vereker
Replied On January 26, 2005 09:06 AM UTC

Yes. Your suggestion works - but as I have 16342 rows, it is rather slow! Any suggestions?

Administrator [Syncfusion]
Replied On January 26, 2005 10:38 AM UTC

You could try this. Only do the dynamic lists if this.dvTest.RowFilter != "". (Here dvTest is from the sample in the other thread.) So, you would use the default lists which are already created (when the filterbar was wired) if there is no filter on the datasource for the grid. You would do this by just skipping the code in CurrentCellShowingDropDown when dvText.RowFIlter == "". Then when this.dvTest.RowFilter was nonempty, build the new lists in CurrentCellShowingDropDown. The thought would be that these lists would be on the filtered table, so that would be much smaller than the original 16000.

Charles Vereker
Replied On January 27, 2005 05:18 AM UTC

Thank you. That works a treat.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;