This is a migrated thread and some comments may be shown as answers.

[Solved] Column filter with a CellTemplated binded to several properties

1 Answer 86 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Yolanda
Top achievements
Rank 1
Yolanda asked on 16 Dec 2010, 06:18 PM
Hello again,

I have a gridview with a column where I show to properties : Activite (Activity) and Etat(State) as follows. The Activity property has a converter that show green color if value =1 and red if value=0.

<telerikGridView:GridViewDataColumn HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}" UniqueName="EtatId"
                                                         DataMemberBinding="{Binding EtatAndActivite}" Header="E" IsReadOnly="True" IsFilterable="True" IsGroupable="False">
                        <telerikGridView:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="{StaticResource InnerRowHeight}" />
                                        <RowDefinition Height="{StaticResource InnerRowHeight}" />
                                        <RowDefinition Height="{StaticResource InnerRowHeight}" />
                                        <RowDefinition Height="{StaticResource InnerRowHeight}" />
                                        <RowDefinition Height="{StaticResource InnerRowHeight}" />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="{StaticResource InnerRowWidth}" />
                                    </Grid.ColumnDefinitions>
                                    <views:ActiveViewControl Grid.Row="1" ActiveBrush="{Binding Activite, Converter={StaticResource ByteToActiveBrushConverter}}" />
                                    <TextBlock Grid.Row="2" Text="{Binding EtatId}"
                                               Foreground="Maroon" FontWeight="Bold" TextAlignment="Center" />
                                    <telerik:RadButton Grid.Row="3" Template="{StaticResource FlagTemplate}" Visibility="{Binding CreationAutomatique, Converter={StaticResource VisibilityConverter}}" />
 
                                </Grid>
                            </DataTemplate>
                        </telerikGridView:GridViewDataColumn.CellTemplate>
                    </telerikGridView:GridViewDataColumn>

The column is binded to theEtatAndActivite  property defined as a tuple from the properties binded in the cell template

public Tuple<String, byte> EtatAndActivite
{
  get
  {
     return new Tuple<string,byte>(EtatId,Activite);
  }
}

I use the default column filter provided. When I click on the filter I receive the good tuple items from data in the gridview. However when I select an item to be filtered all the data are hidden.
Here you can find a screenshot about the filter result. I hope it helps.

How can I solve the problem? I've read some exemples provided by the forum but nothing solves my problem.

exemples:
http://www.telerik.com/community/forums/silverlight/gridview/custom-filter-of-column-bound-to-custom-object.aspx
http://www.telerik.com/community/forums/silverlight/gridview/binding-to-a-dictionary.aspx

Thanks for your help!

1 Answer, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 17 Dec 2010, 02:28 PM
Hi Yolanda,

Filtering cannot be done by a Tuple<T1, T2> since the data engine does not know how to compare such objects. It cannot determine whether one tuple is equal to another tuple.

The only possible way to enable filtering on such a complex type would be to create a new class that will either inherit from this Tuple or aggregate (wrap) it. This new class has to implement the IComparable and IEquatable interfaces. Additionally, it should have its Equals and GetHashCode methods overriden. it should also override the "==" and "!=" operators.

If all of these conditions are met, then the data engine will be able to compare items of this type and thus perform filtering on a list of such objects.

I hope this helps.

Kind regards,
Ross
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
Yolanda
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or