Trying to add a filter to a GridViewDataColumn from a derived class

47 views Asked by At

So I have the following scenario A RadGridView with the bingding for a List

This is My XAML

<telerik:RadGridView 
   x:Name="grid" 
   Grid.Row="0"
   ItemsSource="{Binding BaseClassesList}"
   IsFilteringAllowed="True"
   IsReadOnly="true">
   
   <telerik:RadGridView.Columns>
      <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" />
      <telerik:GridViewDataColumn>
         <DataTemplate DataType="{x:Type DerivedClass}">
            <TextBlock Text="{Binding WhatIWant}"/>
         </DataTemplate>
      </telerik:GridViewDataColumn>
   </telerik:RadGridView.Columns>

</telerik:RadGridView> 

This is my ViewModel

public List<BaseClass> BaseClassesList {get;set;}

This is my BaseClass

public class BaseClass
{
   public string Name{ get; set; }
   public string Filler1{ get; set; }
   public string Filler2{ get; set; }
}

This is my DerivedClass

public class DerivedClass : BaseClass
{
   public string WhatIWant{ get; set; }
}

As you can see, I am binding to a list of BaseClasses and everything is working fine, I can get all the info I want. However, because I'm accessing a list of BaseClass instead of DerivedClass, the GridViewDataColumn isn't able to do its magic and allow the column filter to work. The funnel icon/button doesn't appear. All information is correctly displayed in the grid except for this filter functionality

I tried defining the DataTemplate, DataMemberPath, Filtering flags and nothing so far.

1

There are 1 answers

0
Coelho On BEST ANSWER

So after alot of wall banging and rock smashing I finaly found a solution. But before that, what I didn't say previously for simplicity purposes was that I have a third derived class, and what I wanted to access was on it

public class DerivedDerivedClass : DerivedClass 
{
    public string WhatIWant{ get; set; } //Removed from here
}

The first thing was to move what I wanted to access to the first derivation of the base class

public class DerivedDerivedClass : DerivedClass 
{
    public string WhatIWant{ get; set; } //Removed from here
}
public class DerivedClass : BaseClass 
{
    public string WhatIWant{ get; set; } //Placed here
}

And in the XAML Grid I had to add the DataType and FilterMemberPath to the column. I initially had the DataType on the DataTemplate, but this did not work

<telerik:RadGridView.Columns>
    <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" />
    <telerik:GridViewDataColumn DataType="{x:Type DerivedClass}" FilterMemberPath="WhatIWant">
        <DataTemplate DataType="{x:Type DerivedClass}"> //DataType should not be defined here
            <TextBlock Text="{Binding WhatIWant}"/>
        </DataTemplate>
    </telerik:GridViewDataColumn>
</telerik:RadGridView.Columns>