Custom filter for custom GridViewColumn

3 posts, 1 answers
  1. Boukerroui
    Boukerroui avatar
    4 posts
    Member since:
    Oct 2011

    Posted 14 Jan 2015 Link to this post

    I have ceate a custom filter (inherit from IFilteringControl) with 2 chekbox (values : All and Present) and want to apply it for a custom GridViewColumn
    <telerikGridView:GridViewColumn UniqueName="Commandes_MultiSources"
            HeaderCellStyle="{StaticResource HeaderCellSmallStyle}"
            IsVisible="False"
            IsSortable="False"
            IsReadOnly="True">
        <telerikGridView:GridViewColumn.CellTemplate>
            <DataTemplate>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0" x:Name="Present"
                               TextDecorations="Underline"
                               Cursor="Hand" HorizontalAlignment="Center"
                               Text="{Binding MultiSourcesPresent}"
                               MouseLeftButtonUp="MultiSources_MouseLeftButtonUp"/>
                    <TextBlock Grid.Column="1" x:Name="Tous"
                               TextDecorations="Underline"
                               Cursor="Hand" HorizontalAlignment="Center"
                               Text="{Binding MultiSourcesTous}"
                               MouseLeftButtonUp="MultiSources_MouseLeftButtonUp"/>
                </Grid>
            </DataTemplate>
        </telerikGridView:GridViewColumn.CellTemplate>
        <telerikGridView:GridViewColumn.Header>
            <Grid Width="Auto" HorizontalAlignment="Stretch">
                <Grid.RowDefinitions>
                    <RowDefinition Height="50*"/>
                    <RowDefinition Height="50*"/>
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0" Padding="0 0 0 2" TextAlignment="Center" Text="multi_source"/>
                <Grid Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="50*" />
                        <ColumnDefinition Width="50*"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Column="0" Padding="0 2 20 0" TextAlignment="Center" Text="Present" />
                    <TextBlock Grid.Column="1" Padding="5 2 0 0" TextAlignment="Center" Text="All" />
                </Grid>
            </Grid>
        </telerikGridView:GridViewColumn.Header>
        <telerikGridView:GridViewColumn.FilteringControl>
            <UCPlanipe:FilterControlMultiSource/>
        </telerikGridView:GridViewColumn.FilteringControl>
    </telerikGridView:GridViewColumn>

    in custom filter i cant not use GridViewBoundColumnBase  and i have error (NullReferenceException) in OnFilter method (line 8)
    01.private void OnFilter(object sender, RoutedEventArgs e)
    02.        {
    03.            CreateFilters();
    04.            try
    05.            {
    06.                if (!this.column.DataControl.FilterDescriptors.Contains(this.compositeFilter))
    07.                {
    08.                    this.column.DataControl.FilterDescriptors.Add(this.compositeFilter);
    09.                }
    10.                this.IsActive = true;
    11.                OnFiltredComplet();
    12.            }
    13.            catch (Exception ex)
    14.            {
    15.                // error message is : Object reference not set to an instance of an object
    16.            }
    17.        }
  2. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 16 Jan 2015 Link to this post

    Hi,

    May I ask you to check why this exception is thrown, is this.column null? How do you initialize this.column? Why do you use GridViewColumn and not GridViewBoundColumnBase? How do you intend to perform the filtering in that case? Please note filtering is a data operation which means it is done by building and executing a LINQ query appending proper Where clause over the source collection. 

    Generally, you can refer to our online documentation on how to create a custom filtering control. For more practical project on this you can also check our CustomFilterControls online demo and  the "Custom FilterControl" SDK example running the SDK Samples Browser

    Regards,
    Dimitrina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. Boukerroui
    Boukerroui avatar
    4 posts
    Member since:
    Oct 2011

    Posted 19 Jan 2015 in reply to Dimitrina Link to this post

    Hi,
    tank you for response. My Linq expression  is not find.
Back to Top