Grid loses filterdescriptor

6 posts, 0 answers
  1. B
    B avatar
    74 posts
    Member since:
    Jul 2011

    Posted 14 Dec 2015 Link to this post

     Hi,

    When I have a gridview that is bound to the selectedItem of another gridview and a filterdescriptor then this filter descriptor gets lost when refetching data.

    Steps to reproduce in my test application:

    • Press the fetch button
    • Select the first item and see that the righthand side grid has 1 row
    • Press the fetch button
    • Select the first item again and see that the righthand side grid has 3 rows

    I have the following xaml:

     

    <Window x:Class="TelerikGrid.MainWindow"
            Title="MainWindow"
            WindowStartupLocation="CenterScreen"
            Height="600"
            Width="800">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <StackPanel>
                <Button Content="Fetch" Click="FetchClick"/>
            </StackPanel>
            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="10" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <telerik:RadGridView x:Name="UserListBox"
                                     AutoGenerateColumns="False"
                                     ItemsSource="{Binding Items}">
                    <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Caption}" />
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>
                <telerik:RadGridView Grid.Column="2"
                                     AutoGenerateColumns="False"
                                     ItemsSource="{Binding ElementName=UserListBox, Path=SelectedItem.Children}">
                    <telerik:RadGridView.FilterDescriptors>
                        <telerik:FilterDescriptor Member="IsVisible"
                                                  Operator="IsEqualTo"
                                                  Value="True" />
                    </telerik:RadGridView.FilterDescriptors>
                    <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Caption}" />
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding IsVisible}" />
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>
            </Grid>
        </Grid>
    </Window>

    And the following code behind:

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
     
    namespace TelerikGrid
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                DataContext = this;
            }
     
            public ObservableCollection<Item> Items
            {
                get { return (ObservableCollection<Item>)GetValue(ItemsProperty); }
                set { SetValue(ItemsProperty, value); }
            }
     
            public static readonly DependencyProperty ItemsProperty =
                DependencyProperty.Register("Items", typeof(ObservableCollection<Item>),
                typeof(MainWindow), new PropertyMetadata(null));
     
            private void FetchClick(object sender, RoutedEventArgs e)
            {
                Items = new ObservableCollection<Item>();
                Item item1 = new Item() { Caption = "Item 1" };
                Item item2 = new Item() { Caption = "Item 2" };
                item1.Children.Add(new SubItem() { Caption = "SubItem 1", IsVisible = true });
                item1.Children.Add(new SubItem() { Caption = "SubItem 2", IsVisible = false });
                item1.Children.Add(new SubItem() { Caption = "SubItem 3", IsVisible = false });
                Items.Add(item1);
                Items.Add(item2);
            }
        }
        public class Item : DependencyObject
        {
            public string Caption { get; set; }
     
            public ObservableCollection<SubItem> Children
            {
                get { return (ObservableCollection<SubItem>)GetValue(ChildrenProperty); }
                set { SetValue(ChildrenProperty, value); }
            }
     
            public static readonly DependencyProperty ChildrenProperty =
                DependencyProperty.Register("Children", typeof(ObservableCollection<SubItem>),
                typeof(MainWindow), new PropertyMetadata(null));
     
            public Item()
            {
                Children = new ObservableCollection<SubItem>();
            }
        }
        public class SubItem : DependencyObject
        {
            public string Caption { get; set; }
            public bool IsVisible { get; set; }
        }
    }

     

     

  2. B
    B avatar
    74 posts
    Member since:
    Jul 2011

    Posted 14 Dec 2015 in reply to B Link to this post

    What I am looking for is some kind of workaround that doesnt involve rewriting too much code (the actual application is much bigger and we have a release soon).

     

    I already tried Rebinding which doesnt seem to do anything

    I also tried manually clearing the filter descriptor and adding it again, but this crashes my application

     

     

  3. DevCraft banner
  4. B
    B avatar
    74 posts
    Member since:
    Jul 2011

    Posted 15 Dec 2015 in reply to B Link to this post

    In the demo application it does work when I manually add the filter descriptor again.

    But in the real application this crashes somewhere in Telerik code:

    Unhandled Error in Silverlight Application
    Code: 4004   
    Category: ManagedRuntimeError      
    Message: System.NullReferenceException: Object reference not set to an instance of an object.
       bij Telerik.Windows.Data.Expressions.OperatorValueFilterDescriptorExpressionBuilderBase.CreateBodyExpression()
       bij Telerik.Windows.Data.FilterDescriptor.CreateFilterExpression(ParameterExpression parameterExpression)
       bij Telerik.Windows.Data.FilterDescriptorBase.CreateFilterExpression(Expression instance)
       bij Telerik.Windows.Data.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpression()
       bij Telerik.Windows.Data.CompositeFilterDescriptor.CreateFilterExpression(ParameterExpression parameterExpression)
       bij Telerik.Windows.Data.FilterDescriptorBase.CreateFilterExpression(Expression instance)
       bij Telerik.Windows.Data.CompositeFilterDescriptorCollection.CreateFilterExpression(Expression instance)
       bij Telerik.Windows.Data.ICompositeFilterDescriptorExtensions.GetFilterFunction(ICompositeFilterDescriptor filterDescriptors, Type itemType)
       bij Telerik.Windows.Data.QueryableCollectionView.InitializeInternalList(IQueryable view)
       bij Telerik.Windows.Data.QueryableCollectionView.CreateInternalList()
       bij Telerik.Windows.Data.QueryableCollectionView.EnsureInternalList()
       bij Telerik.Windows.Data.QueryableCollectionView.get_InternalList()
       bij Telerik.Windows.Data.QueryableCollectionView.GetEnumerator()
       bij Telerik.Windows.Data.DataItemCollection.GetFlatEnumerator()
       bij Telerik.Windows.Data.DataItemCollection.GetEnumerator()
       bij Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.NestedLayoutStrategy.EnsureItems()
       bij Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.NestedLayoutStrategy.MeasureOverride(Size constraint)
       bij Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.MeasureOverride(Size availableSize)
       bij System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)    

  5. B
    B avatar
    74 posts
    Member since:
    Jul 2011

    Posted 15 Dec 2015 in reply to B Link to this post

    As a workaround I use the RowLoaded and set the IsEnabled to false (unfortunately Visibility = Collapsed wont collapse the rows), which does seem to work in the real application in all cases.

    Tho that is a slightly different behaviour because it will show the invisible items, but I think that's ok.

    So it is not as urgent

     

  6. B
    B avatar
    74 posts
    Member since:
    Jul 2011

    Posted 16 Dec 2015 in reply to B Link to this post

    Apparently my solution is not good, so I still need a solution for this.

     

     

  7. Stefan X1
    Admin
    Stefan X1 avatar
    520 posts

    Posted 17 Dec 2015 Link to this post

    Hello Bayram,

    I already replied you in the relevant support thread you opened regarding this issue. In order to avoid double posting, I would kindly ask you to continue any further communication regarding this topic in it. However, I will paste my answer here as well:

    "The described behavior would be expected as your are resetting the source collection of RadGridView. This is by design, as there is no guarantee that the type of the newly added items would match the descriptors and columns already defined.

    A possible solution for this scenario is to save the FilterDescriptors before resetting the source collection and add them again after that.

    Additionally, you can take a look at the Filtering section of RadGridView's documentation."

    Regards,
    Stefan X1
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner