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. Image for the cookie policy date
close icon

How do implement an Excel-like autofilter

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)

5 Replies

AD Administrator Syncfusion Team 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.


CV Charles Vereker 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;


CV Charles Vereker January 26, 2005 09:06 AM UTC

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


AD Administrator Syncfusion Team 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.


CV Charles Vereker January 27, 2005 05:18 AM UTC

Thank you. That works a treat.

Loader.
Live Chat Icon For mobile
Up arrow icon