Exception when dynamically changing Items Source + Grouping

2 posts, 0 answers
  1. Konrad Sikorski
    Konrad Sikorski avatar
    23 posts
    Member since:
    Jul 2010

    Posted 17 Sep 2013 Link to this post

    Hi,
    I have few list of different item and I am using one GridView to display theme dynamically. When user press button1 than I am displaying collection1 which contain items of class1, button2 will display collection2 which contains items of class2, ... . For each class the grid has different set of columns. I have problem when I want to change grouping. 

    I am using SL 5.0 and Telerik 2012.3.1129.1050

    In attached example please click button "Item1", than "Item2" and than "Items1" and exception will occurs:

    System.ArgumentNullException was unhandled by user code
      Message=Value cannot be null.
    Parameter name: body
      StackTrace:
           at System.Linq.Expressions.Expression.Lambda(Expression body, String name, Boolean tailCall, IEnumerable`1 parameters)
           at System.Linq.Expressions.Expression.Lambda(Expression body, ParameterExpression[] parameters)
           at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.CreateGroupKeySelectorExpression()
           at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.get_GroupKeySelectorExpression()
           at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilderBase.CreateQuery()
           at Telerik.Windows.Data.Expressions.GroupDescriptorCollectionExpressionBuilder.CreateChildQuery(GroupDescriptorExpressionBuilder childBuilder)
           at Telerik.Windows.Data.Expressions.GroupDescriptorCollectionExpressionBuilder.CreateQuery()
           at Telerik.Windows.Data.QueryableExtensions.GroupBy(IQueryable source, IEnumerable`1 groupDescriptors)
           at Telerik.Windows.Data.QueryableCollectionView.CreateView()
           at Telerik.Windows.Data.QueryableCollectionView.get_QueryableView()
           at Telerik.Windows.Data.QueryableCollectionView.CreateInternalList()
           at Telerik.Windows.Data.QueryableCollectionView.EnsureInternalList()
           at Telerik.Windows.Data.QueryableCollectionView.get_InternalList()
           at Telerik.Windows.Data.QueryableCollectionView.EnsureRootGroup()
           at Telerik.Windows.Data.QueryableCollectionView.get_RootQCVGGroup()
           at Telerik.Windows.Data.QueryableCollectionView.InternalIndexOf(Object item)
           at Telerik.Windows.Data.QueryableCollectionView.TryRestorePreviousCurrency()
           at Telerik.Windows.Data.QueryableCollectionView.InitializeCurrencyOnRefresh(CurrencyRefreshInfo currencyRefreshInfo)
           at Telerik.Windows.Data.QueryableCollectionView.RefreshOverride()
           at Telerik.Windows.Data.QueryableCollectionView.RefreshInternal()
           at Telerik.Windows.Data.QueryableCollectionView.RefreshOrDefer()
           at Telerik.Windows.Data.QueryableCollectionView.InvalidatePagingAndRefresh()
           at Telerik.Windows.Data.QueryableCollectionView.OnGroupDescriptorsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
           at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
           at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
           at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
           at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
           at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
           at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)
           at System.Collections.ObjectModel.Collection`1.Insert(Int32 index, T item)
           at System.Collections.ObjectModel.Collection`1.System.Collections.IList.Insert(Int32 index, Object value)
           at Telerik.Windows.Data.CollectionHelper.Insert(IList target, IEnumerable newItems, Int32 startingIndex, IEqualityComparer itemComparer)
           at Telerik.Windows.Data.ObservableCollectionManager.HandleCollectionChanged(IList sender, NotifyCollectionChangedEventArgs args)
           at Telerik.Windows.Data.ObservableCollectionManager.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args)
           at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
           at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
           at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
           at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
           at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
           at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
           at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)
           at System.Collections.ObjectModel.Collection`1.Add(T item)
           at telerik_gridView_GroupingIssue.MainPage.ucItems1_Click(Object sender, RoutedEventArgs e)
           at System.Windows.Controls.Primitives.ButtonBase.OnClick()
           at System.Windows.Controls.Button.OnClick()
           at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
           at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
           at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)
      InnerException: 

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.ComponentModel;
    using System.Linq;
    using System.Net;
    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.Animation;
    using System.Windows.Shapes;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Data;
     
    namespace telerik_gridView_GroupingIssue
    {
        public partial class MainPage : UserControl
        {
            ObservableCollection<Item1> _items1 = new ObservableCollection<Item1> { new Item1 { Group1 = "G1.1", Name1 = "N1.1" } };
            ObservableCollection<Item2> _items2 = new ObservableCollection<Item2> { new Item2 { Group2 = "G2.1", Name2 = "N2.1" } };
     
            public MainPage()
            {
                InitializeComponent();
            }
     
            private void ucItems1_Click(object sender, RoutedEventArgs e)
            {
                Clear();
     
                ucItemsGrid.Columns.AddRange(
                        new[]
                        {
                            new GridViewDataColumn{UniqueName = "Name1", Header = "Name 1"},
                        }
                    );
     
                ucItemsGrid.SortDescriptors.Add(
                    new SortDescriptor
                    {
                        Member = "Name1",
                        SortDirection = ListSortDirection.Descending
                    });
     
                ucItemsGrid.GroupDescriptors.Add(
                    new GroupDescriptor
                    {
                        Member = "Group1",
                        DisplayContent = "Group 1"
                    });
     
                ucItemsGrid.ItemsSource = _items1;
            }
     
            private void ucItems2_Click(object sender, RoutedEventArgs e)
            {
                Clear();
     
                ucItemsGrid.Columns.AddRange(
                        new[]
                        {
                            new GridViewDataColumn{UniqueName = "Name2", Header = "Name 2"},
                        }
                    );
     
                ucItemsGrid.SortDescriptors.Add(
                    new SortDescriptor
                    {
                        Member = "Name2",
                        SortDirection = ListSortDirection.Descending
                    });
     
                ucItemsGrid.ItemsSource = _items2;
            }
     
            private void Clear()
            {
                ucItemsGrid.GroupDescriptors.Clear();
                ucItemsGrid.SortDescriptors.Clear();
                ucItemsGrid.Columns.Clear();
                ucItemsGrid.ClearValue(RadGridView.ItemsSourceProperty);
                ucItemsGrid.ItemsSource = null;
                ucItemsGrid.Visibility = Visibility.Visible;
                ucItemsGrid.Rebind();
            }
        }
     
        public interface IItem
        {
        }
     
        public class Item1 : IItem
        {
            public string Group1 { get; set; }
            public string Name1 { get; set; }
        }
     
        public class Item2 : IItem
        {
            public string Group2 { get; set; }
            public string Name2 { get; set; }
        }
    }

     
    <UserControl x:Class="telerik_gridView_GroupingIssue.MainPage"
                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                 mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
     
        <StackPanel x:Name="LayoutRoot" Background="White">
            <Button Name="ucItems1" Content="Items1" Click="ucItems1_Click"/>
            <Button Name="ucItems2" Content="Items2" Click="ucItems2_Click"/>
            <telerik:RadGridView Name="ucItemsGrid"
                                 AutoGenerateColumns="False"
                                 IsReadOnly="True"
                                 RowIndicatorVisibility="Collapsed"
                                 CanUserFreezeColumns="False"
                                 />
        </StackPanel>
    </UserControl>
  2. Yoan
    Admin
    Yoan avatar
    1066 posts

    Posted 20 Sep 2013 Link to this post

    Hello Konrad,

    I am sorry, but I can not find any file attached in this thread. However, I can suggest you to test your project with our lates official release - Q2 2013 SP1 (2013.2.724). What is the result you got with the latest binaries? 

    Regards,
    Yoan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
Back to Top