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

RadGridView throws exception when clicking on a row when GroupDescriptors have been added

2 Answers 23 Views
GridView
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 29 Nov 2011, 06:28 AM
Hi,

My RadGridView is throwing an System.InvalidCastException when there are GroupDescriptors applying a grouping to the items in the grid.

The exception is:

[A]DynamicDataType cannot be cast to [B]DynamicDataType. Type A originates from 'DynamicData, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' in a byte array. Type B originates from 'DynamicData, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' in a byte array.
 
  at Telerik.Windows.Data.FuncExtensions.<>c__DisplayClass1`2.<ToUntypedFunc>b__0(Object item)
   at Telerik.Windows.Data.QueryableCollectionViewGroup.FindLastLevelGroupByItem(Object item)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.GetRowForItem(Object item, Boolean forceGroupExpand)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.get_CurrentCell()
   at Telerik.Windows.Controls.GridView.GridViewDataControl.CanCellBecomeCurrent(GridViewCell cell)
   at Telerik.Windows.Controls.GridView.GridViewCell.OnMouseLeftButtonDown(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonDown(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

When the groups are removed from the bar at the top of the grid, there is no problem and I can select the rows of the grid as per normal.

The problem perhaps appears to be related to a piece of code that I use to save the GridDescriptors between refreshes. The method takes in RefreshItemSourceLifetimeStage which is an enum.
This code is called before (AboutToRefresh) and after (FinishedRefresh) the ItemSource is changed with the appropriate argument.
public void RefreshGrid(RefreshItemSourceLifetimeStage stage)
{
    switch (stage)
    {
        case RefreshItemSourceLifetimeStage.AboutToRefresh:
            if (_grid.ItemsSource == null && !_grid.GroupDescriptors.Any())
            {
                // default group descriptor that you get on initial page load
                _savedGroupDescriptors.Add(new GroupDescriptor { Member = "_CallFactorSet.CreatedAt.Year", DisplayContent = "Year Created", SortDirection = ListSortDirection.Descending});
            }
            else
            {
                _savedGroupDescriptors.Clear();
                foreach (var igd in _grid.GroupDescriptors)
                {
                    // we have to clone the objects into the _savedGroupDescriptors collection because otherwise they disappear when the itemsource is refreshed
                    if (igd is GroupDescriptor)
                    {
                        var gd = (GroupDescriptor) igd;
                        _savedGroupDescriptors.Add(new GroupDescriptor { Member = gd.Member, DisplayContent = gd.DisplayContent, SortDirection = gd.SortDirection });
                    }
                    else if (igd is ColumnGroupDescriptor)
                    {
                        var cgd = (ColumnGroupDescriptor) igd;
                        _savedGroupDescriptors.Add(new ColumnGroupDescriptor { Column = cgd.Column, DisplayContent = cgd.DisplayContent, SortDirection = cgd.SortDirection });
                    }
                }
            }
             
            break;
 
        case RefreshItemSourceLifetimeStage.FinishedRefresh:
            _grid.GroupDescriptors.Clear();
            foreach(var groupDescriptor in _savedGroupDescriptors)
            {
                _grid.GroupDescriptors.Add(groupDescriptor);
            }
 
            break;
 
        default:
            throw new ArgumentOutOfRangeException("stage");
    }
}


Any ideas?

2 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 29 Nov 2011, 02:05 PM
Hello James,

Unfortunately with the provided information I cannot guess what is causing the exception.
Could you please send me a sample application which I can debug on my side in order to see what is going on?
Thank you in advance.

All the best,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
James
Top achievements
Rank 1
answered on 30 Nov 2011, 02:07 AM
Hi there, thanks for the reply.
Someone at my office suggested updating to the recent Q3 controls which I did, and the problem seems to have been solved for me.

Cheers,
James
Tags
GridView
Asked by
James
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
James
Top achievements
Rank 1
Share this question
or