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

Sort, Filter, Grouping problem

8 Answers 120 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Maya
Top achievements
Rank 1
Maya asked on 29 Feb 2012, 07:17 PM

Hey,

Unfortunately I have a problem in the sort, filter and group functions in the following case:

Class A
{
string AName;
}
Class B : Class A
{
string BName;
}

Class C

{             

A baseClass;

}

 

The item source is ObservableCollection<C>
I am creating in code behind new GridViewDataColum.

If the binding is
1. " baseClass.AName" =>Everything works.
2. " baseClass.BName " =>The grid view rows are ok.All the data is shown in the correct cells,

But the Filter,Group,Sorting is not working.

 

 What can I do?

8 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 01 Mar 2012, 10:43 AM
Hello,

 In class C is the 'baseClass' of type A, or of type B? In my understanding it should be of type B. 

Kind regards,
Didie
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Maya
Top achievements
Rank 1
answered on 01 Mar 2012, 12:20 PM
No, I have some more classes that derive from class A, and I build dynamicly the grid(using reflection)
0
Maya
Top achievements
Rank 1
answered on 01 Mar 2012, 07:38 PM
someone? help?
0
Maya
Top achievements
Rank 1
answered on 02 Mar 2012, 09:18 AM
Just to be clear, every time that  I build the grid its items only from one type that derives from A.
Maybe this is was missing in my explanation to understand the case.
0
Dimitrina
Telerik team
answered on 02 Mar 2012, 09:36 AM
Hello,

 I am not sure that I understand you the right way. In your previous post you confirmed that the baseClass property in class C is ot type A:

Class C

{             

A baseClass;

}

Now I am not sure what does this mean: I build the grid its items only from one type that derives from A? 

I have prepared a sample project based on your description. Would you please change my sample so that I can see where you have got a problem?

Regards,
Didie
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Maya
Top achievements
Rank 1
answered on 02 Mar 2012, 12:50 PM
Hi,

I'm posting the updated  XAML and Codebehind since I can't attach the source here:

Mainwindow.xaml:
<Window x:Class="RadGridView_WPF_AR_6.MainWindow"
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:my="clr-namespace:RadGridView_WPF_AR_6"
        xmlns:core="clr-namespace:System;assembly=mscorlib"
        Title="MainWindow" Height="700" Width="700">
<Grid>
        <telerik:RadGridView 
                             Name="myGrid" 
                             AutoGenerateColumns="False"
                             Margin="5">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Width="80" DataMemberBinding="{Binding baseClass.AName}" />
                <telerik:GridViewDataColumn Width="Auto" DataMemberBinding="{Binding baseClass.BName}" DataType="{x:Type core:String}"/>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</Window>


MainWindow.xaml.cs:

namespace RadGridView_WPF_AR_6
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            ObservableCollection<C> listC = new ObservableCollection<C>();
            listC.Add(new C(new B("class a")));
            listC.Add(new C(new B("class c")));


            myGrid.ItemsSource = listC;
        }


        public class A
        {
            public string AName { get; set; }
            public A(string a)
            {
                this.AName = a;
            }
            public A()
            {
                this.AName = "default a";
            }
        }
        public class B : A
        {
            public string BName { get; set; }
            public B(string b)
            {
                this.BName = b;
            }
            public B()
            {
                this.BName = "default b";
            }
        }


        public class C
        {
            public A baseClass { get; set; }
            public C(A baseClass)
            {
                this.baseClass = baseClass;
            }
        }
    }
}



The problem is with the second column , the one binded to B's property. 

Regards,
Maya
0
Maya
Top achievements
Rank 1
answered on 06 Mar 2012, 09:36 AM
Hey,

Did you check our example? 

Maya.
0
Nedyalko Nikolov
Telerik team
answered on 06 Mar 2012, 12:55 PM
Hi,

I've checked the provided example.
The problem comes from the fact that baseClass property is from type A which does not have property named "BName" and our data engine cannot create a correct expression in order to get distinct values or to perform sort and group. Bindings on the other hand use reflection in order to get the value, therefore there are data within cells of that column. The only option is to change a little bit your data model.
Let me know if there is something unclear.

All the best,
Nedyalko Nikolov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
GridView
Asked by
Maya
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Maya
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Share this question
or