Create combobox filter

Hello,

I have an SfDatagrid with a FilterRow.

I would like use a Combobox filter with

 - a./ distinct values of the column items as filter.

- b./ custom datasource of items as filter.


For example (a./):

Column cell values:

A

A

B

C

D

D

Filter should be a combobox with items:

A

B

C

D

For example (b./):

Column cell values: any

Filter should be loaded from a List<string> collection.


My second question: how can I set (for example: A) as initial filter?

Thank you very much for help!


6 Replies

SZ SZL September 25, 2022 08:49 AM UTC

Hello, 

I try solve the above task with following code:




        private void PrimaryGrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e)

        {

            if (e.Column.MappingName == nameof(TermekListItemDto.TermekCsoport))

            {

                e.Column.FilterRowEditorType = "ComboBox";

                e.Column.FilterBehavior = Syncfusion.Data.FilterBehavior.StronglyTyped;

                e.Column.FilterRowCondition = FilterRowCondition.Equals;

                //e.Column.AllowBlankFilters = true;

                //e.Column.FilterPredicates.Add(new FilterPredicate() { FilterBehavior = FilterBehavior.StronglyTyped, FilterType = FilterType.Equals, FilterValue = null, PredicateType = PredicateType.Or });

                //e.Column.FilterPredicates.Add(new FilterPredicate() { FilterBehavior = FilterBehavior.StronglyTyped, FilterType = FilterType.Equals, FilterValue = string.Empty, PredicateType = PredicateType.Or });

            }

        }


but I got this exception:

System.InvalidOperationException: 'FilterBehaviour and FilterType are not correct'

   at Syncfusion.Data.Extensions.QueryableExtensions.Predicate(IQueryable source, Object constValue, FilterType filterType, FilterBehavior filterBehaviour, Boolean isCaseSensitive, Type sourceType, Type memberType, Expression memExp, ParameterExpression parameterExpression, String propertyName)

   at Syncfusion.Data.QueryableCollectionViewExtensions.GetPredicates(ParameterExpression parameterExpression, IQueryable source, FilterPredicate filterPredicate, String mappingName, CollectionViewAdv view, Delegate displayLambda, Delegate valueLambda)

   at Syncfusion.Data.QueryableCollectionViewExtensions.GetPredicateExpression(CollectionViewAdv view, IQueryable source, ParameterExpression parameterExpression, String columnName, Boolean returncolExpression, List`1 filterColumns)

   at Syncfusion.Data.QueryableCollectionViewExtensions.GetPredicateExpressionExt(CollectionViewAdv view, IQueryable source, ParameterExpression& parameterExpression, String columnName, Boolean returnColumnExpression)

   at Syncfusion.Data.QueryableCollectionView.GetPredicateExpression(IQueryable source, ParameterExpression& parameterExpression)

   at Syncfusion.Data.QueryableCollectionView.CreateRowFilterPredicate()

   at Syncfusion.Data.QueryableCollectionView.RefreshFilter(Boolean isProgrammatic)

   at Syncfusion.WinForms.DataGrid.GridModel.ApplyColumnFilter(GridColumn column, List`1 filterPredicates)

   at Syncfusion.WinForms.DataGrid.GridModel.FilterColumn(GridColumn column, List`1 filterPredicates)

   at Syncfusion.WinForms.DataGrid.RowFilter.FilterRowCellRenderer`1.ApplyFilters(List`1 filterPredicates, String filterText)

   at Syncfusion.WinForms.ListView.SfComboBox.OnListViewSelectionChanged(Object sender, ItemSelectionChangedEventArgs e)

   at Syncfusion.WinForms.ListView.Interactivity.SelectionController.ProcessSelection(ListViewItemInfo row, Rectangle itemRectangle, MouseEventArgs e)

   at Syncfusion.WinForms.ListView.Interactivity.SelectionController.OnMouseUp(Object sender, MouseEventArgs e)

   at System.Windows.Forms.Control.OnMouseUp(MouseEventArgs e)

   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

   at System.Windows.Forms.Control.WndProc(Message& m)

   at Syncfusion.WinForms.Controls.SfScrollControl.WndProc(Message& msg)

   at Syncfusion.WinForms.ListView.SfListView.WndProc(Message& m)

   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)

   at Interop.User32.DispatchMessageW(MSG& msg)

   at System.Windows.Forms.Application.ComponentManager.Interop.Mso.IMsoComponentManager.FPushMessageLoop(UIntPtr dwComponentID, msoloop uReason, Void* pvLoopData)

   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context)

   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(msoloop reason, ApplicationContext context)

   at System.Windows.Forms.Application.Run(Form mainForm)


I try solve this with some settings combination but cannot solve it.

My Model type is: string? (nullable)

thank you 



DM Dhanasekar Mohanraj Syncfusion Team September 26, 2022 03:18 PM UTC

Hi SZL,

Please find the response for the reported issue below,

Reported issue

Response

 

Distinct values of the column items as filter.

 

 

By default, FilterRow options are loaded as you required. Here, we have attached the tested sample for your reference. Please have a look at this and revert us if you have any concerns about this.

 

 

Custom datasource of items as filter.

 

 

We are a little unclear about your scenario, We suspect that you need to set the DataSource manually. For that, we have already documented the examples. For more information related to set the data source manually, please refer to the below user guide documentation link,

 

UG Link: https://help.syncfusion.com/windowsforms/datagrid/filterrow#filter-based-on-numeric-interval-by-using-the-multiselectcombobox-filter

If we misunderstood your requirement, please provide more information regarding the requirement. This would help us to proceed further.

 

 

I try solve this with some settings combination but cannot solve it.

My Model type is: string? (nullable)

 

 

We have checked the reported issue on our end. But we regret to let you know that we are unable to reproduce the reported issue on our end. If you still facing the reported issue please modify the attached sample based on your scenario and share the video illustration of the reported issue. It will be helpful for us to check the cause of the issue and to provide a solution at the earliest. 


Regards,

Dhanasekar M.


Attachment: FilterRow_8267b873.zip


SZ SZL replied to Dhanasekar Mohanraj September 26, 2022 08:21 PM UTC

Hello,

Thank you very much! Now its working. 

About the exception: I make a mistake, because I have an

OnAutoGeneratingColumn event subscription in base class too and the Combobox filter works only with Equals condition.

I fixed it.

Thank you I have no other question related to this topic now.

Have a nice day!



DM Dhanasekar Mohanraj Syncfusion Team September 27, 2022 02:06 PM UTC

Hi SZL,


We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you.


Regards,

Dhanasekar M.



WI will November 15, 2022 05:45 AM UTC

Go to the Anything menu and select Filter > Control > Combo Box (Drop-Down) Filters on an Output. Select the single-response variable(s) you wish to use as a filter. Select Yes to allow the user to select more than one category in the Combo Box control, or select No to allow the user to select one category only.


Regards,

Will



DM Dhanasekar Mohanraj Syncfusion Team November 16, 2022 02:04 PM UTC

We are a little unclear about your scenario. Can you please share with us the below things?       

        1. Provide more details about your scenario with illustrations?

        2. Can you please share your exact requirement?

We will check the possibilities to achieve your requirement using any workarounds and update you with further details.


Loader.
Up arrow icon