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

Grouping: wrong runtime-type?

4 Answers 48 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steffen
Top achievements
Rank 1
Veteran
Steffen asked on 31 Mar 2010, 04:52 PM
Hi,
can someone tell me how to make the following sample work (grouping by inner ID fails) without modifying the OuterElement-class (in real world that comes from a third-party)?
The problem seems to be that the grouping does not use the right runtime-type but the type of the property(which is an interface that is inherited by SpecialInnerElement). Have a look and you see what I mean.

xaml:
<Window x:Class="RadGridGroupingType.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" 
    xmlns:telerikdata="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data" 
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    Title="Window1" Height="300" Width="300"
    <Grid> 
        <telerik:RadGridView Name="radgv" AutoGenerateColumns="False" ItemsSource="{Binding}"
            <telerik:RadGridView.Columns> 
 
                <telerik:GridViewDataColumn Header="outer ID" DataType="{x:Type sys:Int32}" GroupMemberPath="ID"
                    <telerik:GridViewColumn.CellTemplate> 
                        <DataTemplate> 
                            <TextBlock Text="{Binding Path=ID}"/> 
                        </DataTemplate> 
                    </telerik:GridViewColumn.CellTemplate> 
                </telerik:GridViewDataColumn> 
 
                <telerik:GridViewDataColumn Header="inner ID" DataType="{x:Type sys:Int32}" GroupMemberPath="InnerElement.ID"
                    <telerik:GridViewColumn.CellTemplate> 
                        <DataTemplate> 
                            <TextBlock Text="{Binding Path=InnerElement.ID}"/> 
                        </DataTemplate> 
                    </telerik:GridViewColumn.CellTemplate> 
                </telerik:GridViewDataColumn> 
 
            </telerik:RadGridView.Columns> 
        </telerik:RadGridView> 
    </Grid> 
</Window> 

code-behind:
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
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.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 
using System.Collections.ObjectModel; 
 
namespace RadGridGroupingType 
    /// <summary> 
    /// Interaction logic for Window1.xaml 
    /// </summary> 
    public partial class Window1 : Window 
    { 
        public Window1() 
        { 
            InitializeComponent(); 
 
            ObservableCollection<OuterElement> col = new ObservableCollection<OuterElement>(); 
 
            col.Add(new OuterElement() { ID = 1 }); 
            col.Add(new OuterElement() { ID = 2 }); 
            col.Add(new OuterElement() { ID = 3 }); 
 
            radgv.DataContext = col; 
        } 
    } 
 
    public class OuterElement 
    { 
        public int ID { getset; } 
 
        private SpecialInnerElement m_innerElement = new SpecialInnerElement() { ID = 99 }; 
 
        //public SpecialInnerElement InnerElement //returning the right runtimeType: grouping works 
        public IInnerElement InnerElement         //returning interface: grouping does not work 
        { 
            get { return m_innerElement; } 
        } 
    } 
 
    public interface IInnerElement 
    { 
        //"does not matter"; 
    } 
 
    public class SpecialInnerElement: IInnerElement 
    { 
        public int ID { getset; } 
    } 

Best Regards
Steffen

4 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 02 Apr 2010, 02:44 PM
Hello Steffen,

The interface should have this property if you want to be able to group. Our data engine is working directly with your interface. Since it does not have this property the expressions that we are building will fail.

Your interface should look like this in case you want to group by its property:

    public interface IInnerElement

    {

        int ID { get; set; }

    }



You might be wandering: Then why do I see values in the second column? This is because cells display their values via a Binding which is not very picky about types.

Let me know if you have any questions.

Best wishes,
Ross
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
Steffen
Top achievements
Rank 1
Veteran
answered on 06 Apr 2010, 08:43 AM
Hi,
thank you for the response. That is pretty much what I was guessing.
The problem is that I can not change the interface. Is there a way to build the grouping expression manually in the grouping-event (based on the column's unique name)? Or maybe this can be somehow achieved by using a ValueConverter?
Actually the outerElemnt is the RadScheduler's Occuence, the interface is IAppointment and the innerElement is my own MyAppointment-type. So how could I bind a collection of Occurences to a GridView which also shows properties of MyAppointment  (returned by Occurences.Appointment as IAppointment) and still be able to group?


Best
Regards
Steffen
0
Accepted
Rossen Hristov
Telerik team
answered on 06 Apr 2010, 09:10 AM
Hi Steffen,

In case you cannot change the interface, you will have to build wrappers around your classes. The wrappers will expose the correct properties. Then bind the grid to this intermediate wrapper layer. I cannot think of an easier way to solve this issue.

Regards,
Ross
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
Steffen
Top achievements
Rank 1
Veteran
answered on 06 Apr 2010, 10:08 AM
Hi,
I'll try that.

Best Regards
Steffen
Tags
GridView
Asked by
Steffen
Top achievements
Rank 1
Veteran
Answers by
Rossen Hristov
Telerik team
Steffen
Top achievements
Rank 1
Veteran
Share this question
or