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

Grouping by entity type with RadGridView and QueryableCollectionView

14 Answers 175 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Frederic Ouellet
Top achievements
Rank 1
Frederic Ouellet asked on 22 Mar 2010, 06:27 PM
Hi,

How can i group by entity type in a grid.
I have a few entity type derived from a base one.
I want to display all of them (common property) in a read-only grid grouped by their type.
I use TPT for my types (one table for each type), so I don't have a column containing the type.

Frederic

14 Answers, 1 is accepted

Sort by
0
Accepted
Stefan Dobrev
Telerik team
answered on 23 Mar 2010, 05:46 PM
Hi Frederic Ouellet,

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.
0
Frederic Ouellet
Top achievements
Rank 1
answered on 23 Mar 2010, 05:58 PM
Thank you
0
Adam
Top achievements
Rank 1
answered on 29 Jul 2011, 03:19 PM
I used your example here to group my RadGridViews by two types.  I bind them to an ObservableCollection<object> so that I can freely add objects of either type.  The user can move items between two of these GridViews at will.  The problem comes in when one of the GridViews was instantiated with only one type contained within its bound collection.  If this is the case, the adding an object of another type causes an ArgumentException to be thrown.  This is not the case if both or no groups are present when the controls is instantiated...

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()


0
Nedyalko Nikolov
Telerik team
answered on 04 Aug 2011, 08:39 AM
Hello Adam,

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.

All the best,
Nedyalko Nikolov
the Telerik team

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

0
Adam
Top achievements
Rank 1
answered on 22 Aug 2011, 02:12 PM
Sorry I took so long to get back.  The issue persists with my your latest internal build (downloaded 8/19).  The same exception message is still displayed.
0
Yordanka
Telerik team
answered on 25 Aug 2011, 12:38 PM
Hi Adam,

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 >>

0
Adam
Top achievements
Rank 1
answered on 25 Aug 2011, 03:47 PM
In trying to replicate a simple example to aid you I cannot seem to reproduce the issue.  The only difference that I can see between the two projects is that one is using an MVVM pattern and one is not.  Thought this may help to narrow down the issue.
0
Yordanka
Telerik team
answered on 25 Aug 2011, 04:03 PM
Hello Adam,

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 >>

0
Adam
Top achievements
Rank 1
answered on 01 Sep 2011, 10:00 PM
I have more information that hopefully will help solve this issue.  The crash only happens if the GridView controls are reloaded containing only one of the two types.  The initial instance of the controls have no problem.  Also, if the GridView controls are reloaded containing neither of the two types there is no problem.

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.
0
Yordanka
Telerik team
answered on 02 Sep 2011, 07:58 AM
Hi Adam,

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 >>

0
Adam
Top achievements
Rank 1
answered on 02 Sep 2011, 12:51 PM
Wonderful, thanks!
0
Adam
Top achievements
Rank 1
answered on 08 Sep 2011, 08:39 PM
Haven't seen another internal build.  The last one is dated 8/23.  Any idea when this may be released?
0
Adam
Top achievements
Rank 1
answered on 12 Sep 2011, 09:03 PM
Worked like a charm, thanks for all of your help in this.
0
Hristo
Telerik team
answered on 13 Sep 2011, 10:51 AM
Hi Adam,

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 >>

Tags
GridView
Asked by
Frederic Ouellet
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Frederic Ouellet
Top achievements
Rank 1
Adam
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Yordanka
Telerik team
Hristo
Telerik team
Share this question
or