
14 Answers, 1 is accepted
Please find attached a custom group descriptor implementation that can be used to group by arbitrary LINQ expressions. In the sample I'm grouping by the return value of object.GetType() method.
Hope this helps,
Stefan Dobrev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items.


The RadGridViewCode:
<
telerik:RadGridView
x:Name
=
"radgvAddedContactsList"
Margin
=
"0"
ShowGroupPanel
=
"False"
GridLinesVisibility
=
"Horizontal"
IsReadOnly
=
"True"
SelectionMode
=
"Multiple"
CanUserFreezeColumns
=
"False"
CanUserReorderColumns
=
"False"
CanUserResizeColumns
=
"False"
CanUserDeleteRows
=
"False"
CanUserInsertRows
=
"False"
Grid.Column
=
"2"
d:LayoutOverrides
=
"Width"
ItemsSource
=
"{Binding SelectedContactsAndCategories}"
AutoGenerateColumns
=
"False"
FontSize
=
"12"
GroupHeaderTemplate
=
"{StaticResource NewCategoryGroupHeaderTemplate}"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Assigned Contacts and Categories"
IsReorderable
=
"False"
IsResizable
=
"False"
IsReadOnly
=
"True"
IsGroupable
=
"False"
IsFilterable
=
"False"
Width
=
"*"
CellTemplateSelector
=
"{StaticResource CategoryContactsGridViewTemplateSelector}"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
The GroupHeaderTemplate:
<
DataTemplate
x:Key
=
"NewCategoryGroupHeaderTemplate"
>
<
TextBlock
Text
=
"{Binding Group.Key.Name, Converter={StaticResource TypeNameConverter}}"
/>
</
DataTemplate
>
The CellTemplateSelector and corresponding DataTemplates:
public
class
CategorySettingsGridViewTemplateSelector : DataTemplateSelector
{
public
override
System.Windows.DataTemplate SelectTemplate(
object
item, System.Windows.DependencyObject container)
{
DataTemplate ret =
null
;
if
(item
is
Category)
{
ret = App.Current.Resources[
"CategoryGridViewItemTemplate"
]
as
DataTemplate;
}
else
if
(item
is
TXTUnit)
{
ret = App.Current.Resources[
"ContactGridViewItemTemplate"
]
as
DataTemplate;
}
return
ret;
}
}
<
DataTemplate
x:Key
=
"CategoryGridViewItemTemplate"
>
<
TextBlock
Text
=
"{Binding Name}"
/>
</
DataTemplate
>
<
DataTemplate
x:Key
=
"ContactGridViewItemTemplate"
>
<
TextBlock
Text
=
"{Binding Alias}"
/>
</
DataTemplate
>
The Converter mentioned in the GroupHeaderTemplate simply takes type name .ToString() value passed in and assigns a more user friendly name.
Finally the StackTrace:
at System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type targetType)
at System.Collections.Generic.List`1.System.Collections.IList.Add(Object item)
at Telerik.Windows.Data.QueryableCollectionViewGroup.GetRootGroupForItem(Object item, Type itemType, IEnumerable`1 groupDescriptors) in c:\TB\101\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Data\Grouping\QueryableCollectionViewGroup.cs:line 401
at Telerik.Windows.Data.QueryableCollectionViewGroup.GetGroupByItemAndLevel(Object item, Type itemType, IEnumerable`1 groupDescriptors, Int32 groupLevel) in c:\TB\101\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Data\Grouping\QueryableCollectionViewGroup.cs:line 408
at Telerik.Windows.Data.QueryableCollectionViewGroup.ProcessAdded(Object itemToAdd, ItemAction action) in c:\TB\101\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Data\Grouping\QueryableCollectionViewGroup.cs:line 479
at Telerik.Windows.Data.QueryableCollectionViewGroup.ProcessOnItemAction(Object item, ItemAction action) in c:\TB\101\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Data\Grouping\QueryableCollectionViewGroup.cs:line 384
at Telerik.Windows.Data.QueryableCollectionViewGroupRoot.ProcessOnItemAction(Object item, ItemAction action) in c:\TB\101\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Data\Grouping\QueryableCollectionViewGroupRoot.cs:line 168
at Telerik.Windows.Data.QueryableCollectionView.ProcessSynchronousCollectionChanged(NotifyCollectionChangedEventArgs args) in c:\TB\101\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1240
at Telerik.Windows.Data.QueryableCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args) in c:\TB\101\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1153
at Telerik.Windows.Data.QueryableCollectionView.OnSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args) in c:\TB\101\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1596
at Telerik.Windows.Data.QueryableCollectionView.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args) in c:\TB\101\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1581
at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args) in c:\TB\101\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\WeakEvents\WeakEvent.cs:line 33
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at TrAVL_TXT.CategoryGroupSettingsViewModel.<HandleAssignContactToCategoryGroup>b__c(Object selecteditem) in C:\Documents and Settings\aburdette\My Documents\Visual Studio 2010\Projects\NPG\TrAVL TXT\TrAVL TXT\ViewModel\CategoryGroupSettingsViewModel.cs:line 174
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at TrAVL_TXT.CategoryGroupSettingsViewModel.HandleAssignContactToCategoryGroup() in C:\Documents and Settings\aburdette\My Documents\Visual Studio 2010\Projects\NPG\TrAVL TXT\TrAVL TXT\ViewModel\CategoryGroupSettingsViewModel.cs:line 170
at TrAVL_TXT.CategoryGroupSettingsViewModel.<.ctor>b__1() in C:\Documents and Settings\aburdette\My Documents\Visual Studio 2010\Projects\NPG\TrAVL TXT\TrAVL TXT\ViewModel\CategoryGroupSettingsViewModel.cs:line 155
at GalaSoft.MvvmLight.Command.RelayCommand.Execute(Object parameter)
at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at Telerik.Windows.Controls.RadButton.OnClick() in c:\TB\101\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\Buttons\RadButton.cs:line 357
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at TrAVL_TXT.App.Main() in C:\Documents and Settings\aburdette\My Documents\Visual Studio 2010\Projects\NPG\TrAVL TXT\TrAVL TXT\obj\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Could you please try your scenario with our latest internal build, since we've fixed a related bug lately?
If the problem persists please send me a sample project which I can debug on my side in order to see what is going on.
Thank you in advance.
Nedyalko Nikolov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

We currently investigate the problem. We will contact you as soon as we have more information.
Kind regards,
Yordanka
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Thank you for the details. We appreciate your cooperation.
Greetings,
Yordanka
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

More concisely, it seems that on load the GridView assumes that only the current type of data object, if one is present,
can be contained.
Thank you once again for the feedback.
The issue is already resolved and the fix for it will be part of the latest internal build next week.
Regards,
Yordanka
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>



I am glad to hear that you found our build .912 useful.
All the best,
Hristo
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>