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 to correctly manage filtered combo-boxes on sfDataGrid

Hi,

I'm not able to correctly manage an sfDataGrid with a combo-box cell inside it where the combo-box itemSource changes according to the current selected record (the combo-box list is filtered).
I have implemented a possible solution that is not acceptable cause some side effects.
I have explained everything in the solution I attach below.
Inside it you can find both che C# project and a video that better explains my requirements and my actual not correct solution.
Have you any sugestion that can help me to correctly implement this filtered behavior ?
Thank you,

Silvio

Attachment: GridFilteredCombo_764a47ab.zip

7 Replies

MK Muthukumar Kalyanasundaram Syncfusion Team July 14, 2017 04:02 AM UTC

Hi Silvio, 
 
Thank you for contacting Syncfusion support. 

We have checked your provided video file. We are unable to get your exact requirement, we suspect that your requirement is to Filter the ItemsSource bounded to the ComboBox. For example if we have ItemsSource collection A,B and C for bounding it to the comboBox. If the cell Display value is B means, your requirement is to filter the ItemsSource collection with B and at the result bound the remaining collection (A & C) in to the ComboBox.  If your requirement is different from this, could you please share some more information about your requirement clearly ?.  This would be more helpful for us to proceed further. 

If you want to bind the different itemsource to each row of combobox, you can refer the below link 
   
Please let us know if you have any query. 
 
Regards, 
Muthukumar K 



SI Silvio July 14, 2017 12:31 PM UTC

Hi, 

thank you for this reply and your example.

Yes, probably your suspections are correct.

In fact, my need is not to change the ItemsSource for each different row in the grid.

My need is to have the possibility, having a unique global list for the ItemSource, to filter its content according to the current row (and relative binded record) and let the user be able to select, for each different record, only a subset (filtered) of the whole global ItemSource collection.

It is clearer now? Thank you.

Have a nice week end.


Silvio S.



MK Muthukumar Kalyanasundaram Syncfusion Team July 18, 2017 06:15 PM UTC

Hi Silvio, 

Sorry for the delay. 

We have checked your query. It is not possible to achieve your requirement based on SelectedItem. But you can achieve your requirement to filter and set ItemsSource by writing customer renderer as in the below KB article. 
  

In the above article ShipCount column ItemsSource are queried based on ShipCountry via ItemsSourceSelector. Please let us know if this help us to achieve your requirement.  

Regards, 
Muthukumar K 



SI Silvio July 20, 2017 09:14 AM UTC

Dear Muthukumar


I have another different idea, if it is possible.

Surely when the ComboBox is opened an SfDataGrid is displayed.

So, is it possible to set View.Filter Predicate property of this SfDataGrid in order to implement in this passed method all my filtering related to the current grid selection?

If it is, can you show me how and where to set it ?

Thank you.


Silvio



MK Muthukumar Kalyanasundaram Syncfusion Team July 24, 2017 05:45 PM UTC

Hi Silvio, 
 
Thanks for the update. 
 
We have checked your query. The purpose of View.Filter predicate is to filter SfDataGrid only, that we can’t use to filter ItemsSource for ComboBox. In below attached sample, we have created custom column and filter the comboBox data as shown like below code, 
 
Code Snippet: Xaml 
 
<local:GridComboBoxColumnExt DisplayMemberPath="CityName" 
                        MappingName="CityID" 
                        SelectedValuePath="CityID"> 
    <local:GridComboBoxColumnExt.ItemsSourceSelectorSelector> 
        <local:ItemsSourceSelectorSelector/> 
    </local:GridComboBoxColumnExt.ItemsSourceSelectorSelector> 
</local:GridComboBoxColumnExt> 
 
 
Code Snippet: C# 
 
public class ItemsSourceSelectorSelector : IItemsSourceSelector 
{ 
    public IEnumerable GetItemsSource(object record, object dataContext) 
    { 
        if (record == null) 
            return null;         
 
        //write ItemSource based on your record. 
         
    } 
} 
 
 
 
Please let us know if you have any query. 
 
Regards, 
Muthukumar K 



SI Silvio July 25, 2017 02:28 PM UTC

Dear Muthukumar,


the last example you have proposed me should be similar to what I'd like to obtain.

By I don't like to use GridComboBoxColumn in my SfDataGrid.

I'd like to use, instead, a GridMultiColumnDropDownList column that let me to show to the user more columns for each record.

It was for this reason that I sugested you if it was possible to use View.Filter Predicate, since it seems to me that this column type uses an SfDataGrid to display the popup where the user selects a record.

So, is it possible to have an example similar to the last one when a GridMultiColumnDropDownList column is used ?

Thank you,

Silvio



MK Muthukumar Kalyanasundaram Syncfusion Team August 1, 2017 01:01 AM UTC

Hi Silvio, 
 
Sorry for the delay. 
 
As per your requirement. We have prepared sample with GridMultiColumnDropDownList control. For your reference, we have attached sample in below location. Could you please refer to it. 
 
Code Snippet: Xaml 
 
<local:GridMultiColumnExt DisplayMember="CityName" ItemsSource="{Binding OrderList}" 
                    MappingName="CityID" ValueMember="CityID" > 
    <local:GridMultiColumnExt.ItemsSourceSelectorSelector> 
        <local:ItemsSourceSelectorSelector/> 
    </local:GridMultiColumnExt.ItemsSourceSelectorSelector> 
</local:GridMultiColumnExt> 
 
 
You can use GridCellMultiColumnDropDownRenderer instead of GridCellComboBoxRenderer as like below code, 
 
Code Snippet: C# 
public class GridCellMultiComboBoxRendererExt : GridCellMultiColumnDropDownRenderer  
{ 
    public GridCellMultiComboBoxRendererExt() : base() 
    { } 
 
    public override bool CanUpdateBinding(GridColumn column) 
    { 
        return true;  
    } 
    public override void OnInitializeEditElement(DataColumnBase dataColumn, SfMultiColumnDropDownControl uiElement, object dataContext) 
    { 
        var customColumn = (GridMultiColumnExt)dataColumn.GridColumn; 
        //Setting ItemsSource for GridComboBoxColumn 
        if (customColumn != null && customColumn.ItemsSourceSelectorSelector != null) 
        { 
            object value = customColumn.ItemsSourceSelectorSelector.GetItemsSource(dataContext, DataGrid.DataContext); 
            customColumn.ItemsSource = value as IEnumerable; 
        } 
        base.OnInitializeEditElement(dataColumn, uiElement, dataContext); 
    } 
} 
 
 
public class ItemsSourceSelectorSelector : IItemsSourceSelector 
{ 
    public IEnumerable GetItemsSource(object record, object dataContext) 
    { 
        if (record == null) 
            return null; 
        //write ItemSource based on your record. 
    } 
} 
 
 
Please let us know if you have any query. 
 
Regards, 
Muthukumar K 


Loader.
Live Chat Icon For mobile
Up arrow icon