Load Filter Settings on enums does not check the values in the filter

1 Answer 13 Views
GridView
Juan
Top achievements
Rank 1
Juan asked on 11 May 2024, 10:12 PM | edited on 12 May 2024, 08:26 PM

Hi, I followed the steps on how to save / load filters on my c# WPF app from this link and it is working correctly

https://docs.telerik.com/devtools/wpf/controls/radgridview/filtering/how-to/howto-save-and-load-filter-settings

My grid is filtered and it works for all the columns (Just in case it wasn’t clear, the grid is indeed filtered by Source and Order Id). For all the fields that are strings, the filters look good when it shows:

But the fields that are enums, The header shows the icon as if a filter has been applied, but when it shows me the list, the values are not checked:


Code:

<telerik:RadGridView 
    x:Name="DesignQueueOrderGridView"
    ShowGroupPanel="False" 
    AutoGenerateColumns="False" 
    ItemsSource="{Binding FilteredDesignQueueOrderViewModels}"
    RowDetailsVisibilityMode="Visible"
    RowIndicatorVisibility="Collapsed"
    Grid.Row="1"
    VerticalAlignment="Top"
    RowStyle="{StaticResource RowStyleOdd}" 
    AlternationCount="2" 
    AlternateRowStyle="{StaticResource RowStyleEven}"
    CanUserSortColumns="False">

 

<telerik:GridViewDataColumn 
        UniqueName="ImageSource"
        Header="Source"
        HeaderTextAlignment="Center"
        DataMemberBinding="{Binding ImageSource}"
        IsReadOnly="True">

<telerik:GridViewDataColumn DataMemberBinding="{Binding UserId}" UniqueName="UserId"

                

                            HeaderTextAlignment="Center" 
                            Header="User Id" 
                            IsReadOnly="True"/>

              </telerik:GridViewDataColumn>

Enum:

[DataContract]
public enum ImageSource
{
    [EnumMember]
    Unknown = 0,

    [EnumMember]
    OnlineDesigner = 1

}

public void LoadColumnFilters(IList<FilterSetting> savedSettings)
{
    Application.Current.Dispatcher.Invoke(() =>
    {
        GridViewDataControl.FilterDescriptors.SuspendNotifications();

        foreach (FilterSetting setting in savedSettings)
        {
            Telerik.Windows.Controls.GridViewColumn column = GridViewDataControl.Columns[setting.ColumnUniqueName];

            if (column is null)
                continue;

            IColumnFilterDescriptor columnFilter = column.ColumnFilterDescriptor;

            if (setting.SelectedDistinctValues is not null)
            {
                foreach (string? distinctValue in setting.SelectedDistinctValues)
                {
                    columnFilter.DistinctFilter.AddDistinctValue(distinctValue);
                }
            }
        }

        GridViewDataControl.FilterDescriptors.ResumeNotifications();
    });
}

 

Thank you in advance! Juan

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 13 May 2024, 08:08 AM

Hello Juan,

The AddDistinctValue method of the DistinctFilter allows you to provide any object in the filter. However, in order to make it work as expected you should provide the corresponding object type and also the associated object should be contained in the cells of the column. In your case, you can should cast the value to the enum type:

foreach (string? distinctValue in setting.SelectedDistinctValues)
{
        ImageSource convertedEnumValue = MyConvertDistinctValueToTheProperTypeMethod(distinctValue);
	columnFilter.DistinctFilter.AddDistinctValue(convertedEnumValue);
}

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Juan
Top achievements
Rank 1
commented on 13 May 2024, 12:51 PM

@Martin Ivanov that worked like a charm, Thank you very much for the quick answer! :D 
Tags
GridView
Asked by
Juan
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or