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

Child radgridview sorting problem

7 Answers 158 Views
GridView
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 12 Jul 2011, 12:50 PM
Hi,
I am trying to bind a hierachical gridview using entity framework 4.0. (tables: Countries with Districts)
Whenever i try to add a child table definition to the main gridview  the ability to sort the child gridview is lost ( when setting the property relation):
d.Relation = new Telerik.Windows.Data.PropertyRelation("Districts");

If i manually add the datasource then sorting works perfectly. Is this the normal behaviour ? Am i doing something wrong?

GridViewTableDefinition d = new GridViewTableDefinition();
d.DataSource = new SofERPEntities().Districts.Where(z=>z.CountryId==5).ToList();   => sorting in child gridview works
 //d.Relation = new Telerik.Windows.Data.PropertyRelation("Districts");  => sorting in child gridview not working
this.radGridView1.ChildTableDefinitions.Add(d);


7 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 14 Jul 2011, 09:24 AM
Hi John,

 I have prepared a sample project in order to test the problem that you are facing.

I have created three RadGridViews with different definition of the hierarchy:
1. The child table definition is added in code behind (as in your case).
2. The child table definition is added in the XAML:

<telerik:RadGridView.ChildTableDefinitions>
               <telerik:GridViewTableDefinition>
                   <telerik:GridViewTableDefinition.Relation>
                       <telerik:PropertyRelation ParentPropertyName="Players"/>
                   </telerik:GridViewTableDefinition.Relation>
               </telerik:GridViewTableDefinition>
           </telerik:RadGridView.ChildTableDefinitions>

3. A RowDetailsTemplate is used:
<telerik:RadGridView Grid.Row="2"
Name="clubsGridRowDetails"
ItemsSource="{Binding Clubs}"
RowDetailsTemplate="{StaticResource RowDetailsTemplate}">

In the three cases the sorting works fine.

May you please review the sample project and share what the difference in your project is? 

Regards,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
John
Top achievements
Rank 1
answered on 14 Jul 2011, 12:03 PM
Thank you for your examples, Didie. After a closer look , the only difference between my project and the samples you gave me is that i use the Entity Framework generated classes. Sorting is still not working for me in this case. I modified on your project the static  "GetClubs" method to :
 
public static ObservableCollection<Country> GetCountries()
 {
            MyEntities entities = new MyEntities ();
            return new ObservableCollection<Country>(entities.Country);           
 }

where "Country" is an EF generated class and i did the following to load the grid:

 this.clubsGrid.ItemsSource = Club.GetCountries();
 this.clubsGrid.TableDefinition.ChildTableDefinitions.Add(
                new GridViewTableDefinition
                {
                    Relation = new PropertyRelation("District")
                });


Even though countries and districts are loaded in the grid, i can only sort the countries table and not the child table (districts).
0
Dimitrina
Telerik team
answered on 18 Jul 2011, 01:56 PM
Hi John,

 A have tested the same project with Entity Framework object and still the Hierarchy is working fine.

I have used this code:

clubsGrid.ItemsSource = new ClubsEntities3().Clubs;
 
            this.clubsGrid.TableDefinition.ChildTableDefinitions.Add(
                new GridViewTableDefinition
                {
                    Relation = new PropertyRelation("Players")
                });

The Players table(PlayerId, Name, ClubId) has a ClubId foreign key constraint to the Clubs table(ClubId, Name).

Are you using this approach? How do your tables differ from these ones?

Greetings,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
John
Top achievements
Rank 1
answered on 18 Jul 2011, 02:31 PM
Can you please send me a sample project using EntityFramework? I did the same thing and the sort in the child grid does not work.
0
Dimitrina
Telerik team
answered on 18 Jul 2011, 04:11 PM
Hi John,

I am attaching a sample project. You may just need to change the connection string to connect to your Database appropriately.


Kind regards,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Dimitrina
Telerik team
answered on 19 Jul 2011, 04:01 PM
Hello John,

 Indeed you are right that the sorting of the child grid is not working. I apologize for this misunderstanding.

We are going to further investigate this and inform you when we have figured out why this happens.

Greetings,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Dimitrina
Telerik team
answered on 08 Aug 2011, 02:13 PM
Hi John,

 I am updating this forum thread, as we have already answered you in the support ticket.

Child sorting does not work because the Entity Framework returns child properties like Club.Players as a special type which inherits from ICollectionView and has its CanSort property set to false. Whenever RadGridView is bound to a collection of type ICollectionView, the grid respects the CanSort property - if this property is set to false, as the case is, the grid will not be able to sort. 

If you try the same scenario with Microsoft's DataGrid you will get the same behavior. 

Luckily there are various workarounds that you could employ. For example you can try the following modifications to MainWindow.xaml and MainWindow.xaml.cs:

Copy Code
<Window x:Class="RadGridView_WPF_AR_11.MainWindow"
        xmlns:my="clr-namespace:RadGridView_WPF_AR_11.SampleData"
        Title="MainWindow" Height="700" Width="700">
    <Window.Resources>
        <my:MyViewModel x:Key="MyViewModel"/>
    </Window.Resources>
    <Grid>
        <telerik:RadGridView Grid.Row="0" 
                             Name="clubsGrid" 
                             AutoGenerateColumns="True"
                             Margin="5">
            <telerik:RadGridView.Columns>
                <telerik:GridViewToggleRowDetailsColumn/>
            </telerik:RadGridView.Columns>
            <telerik:RadGridView.RowDetailsTemplate>
                <DataTemplate>
                    <telerik:RadGridView Name="playersGrid" 
                                     Loaded="playersGrid_Loaded"
                                     AutoGenerateColumns="True">
                    </telerik:RadGridView>
                </DataTemplate>
            </telerik:RadGridView.RowDetailsTemplate>
        </telerik:RadGridView>
    </Grid>
</Window>

Copy Code
using System.Linq;
using System.Windows;
using Telerik.Windows.Controls.GridView;
  
namespace RadGridView_WPF_AR_11
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        ClubsEntities3 entities;
  
        public MainWindow()
        {
            InitializeComponent();
  
            this.entities = new ClubsEntities3();
  
            clubsGrid.ItemsSource = this.entities.Clubs;
        }
  
        private void playersGrid_Loaded(object sender, RoutedEventArgs e)
        {
            var dataGrid = sender as GridViewDataControl;
            var club = dataGrid.DataContext as Club;
  
            var players = this.entities.Players.Where(p => p.ClubId == club.ClubId);
  
            dataGrid.ItemsSource = players;
        }
    }
}
Regards,
Didie
the Telerik team

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

Tags
GridView
Asked by
John
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
John
Top achievements
Rank 1
Share this question
or