GridComboBoxColumn Filter DropDownListVIew

Hi,

I need to filter the DropDownList of GridComboBoxColumn. I would replicate something like this

sfComboBox.DropDownListView.View.Filter = (delegate (object r) { return (int)(r as DataRow)["DELETED"] != 0; });


Is that possible?

Many thanks for considering my request.


3 Replies

MS Malini Selvarasu Syncfusion Team August 9, 2024 08:23 AM UTC

Hi Remigio Fattori,
We have thoroughly reviewed your scenario and, based on our analysis, it appears that you need to filter the DropDownList items within the GridComboBoxColumn. This objective can be accomplished using the following methods:
Solution 1:
You can filter the `SfComboBox` DropDownList within the `GridComboBoxCellRenderer`'s `OnInitializeEditElement` method. We have adjusted your code snippet accordingly and provided a sample to illustrate this approach. Please refer to the code snippet below:
Code Snippet:
public class GridComboBoxCellRendererExt : GridComboBoxCellRenderer
{
    protected override void OnInitializeEditElement(DataColumnBase column, RowColumnIndex rowColumnIndex, SfComboBox uiElement)
    {
        base.OnInitializeEditElement(column, rowColumnIndex, uiElement);
        uiElement.DropDownListView.View.Filter = (object r) => (int)r != 0;
        uiElement.DropDownListView.View.RefreshFilter();
    }
}

 Solution 2:
Alternatively, you can directly evaluate whether the dropdown item meets your criteria within the `GridComboBoxCellRenderer`'s `OnInitializeEditElement` method. We have prepared a sample to demonstrate this approach and attached it for your review. Please examine the provided sample and code snippet, and let us know if you have any further questions.
Code Snippet:
public class GridComboBoxCellRendererExt : GridComboBoxCellRenderer
{
    protected override void OnInitializeEditElement(DataColumnBase column, RowColumnIndex rowColumnIndex, SfComboBox uiElement)
    {
        base.OnInitializeEditElement(column, rowColumnIndex, uiElement);
        uiElement.DropDownListView.View.Filter = FilterItem;
        uiElement.DropDownListView.View.RefreshFilter();
    }
    private bool FilterItem(object data)
    {
        return (int)data != 0;
    }
}

If we have misunderstood your requirement, kindly provide more details so that we can assist you further. Thank you for your understanding and cooperation.

Regards,

Malini Selvarasu

 


Attachment: SfDataGrid_Demo_ed0bf58f.zip


RF Remigio Fattori September 2, 2024 05:01 PM UTC

it works! 

Thank you



MS Malini Selvarasu Syncfusion Team September 3, 2024 09:11 AM UTC

Hi Remigio Fattori,

We are glad that your query was addressed. If you have any other queries, please create a new forum. We are closing this forum.

Regards,
Malini Selvarasu

Loader.
Up arrow icon