Мой RadGridView генерирует исключение System.InvalidCastException, когда существуют дескрипторы GroupDescriptors, применяющие группирование к элементам в сетке.
Исключение довольно бесполезно:
[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)
Когда группыпосле удаления из панели в верхней части сетки проблем нет, и я могу выбрать строки сетки в обычном порядке.
Возможно, проблема связана с фрагментом кода, который я использую длясохраните GridDescriptors между обновлениями.Метод получает в RefreshItemSourceLifetimeStage, который является перечислением.Этот код вызывается до (AboutToRefresh) и после (FinishedRefresh) ItemSource изменяется с соответствующим аргументом.
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");
}
}
Есть идеи?