RadGridView Master-detail problem

5 posts, 0 answers
  1. Nebojsa Danilovic
    Nebojsa Danilovic avatar
    18 posts
    Member since:
    Feb 2010

    Posted 02 Mar 2010 Link to this post

    Hi,
    I am a beginner and I have a problem with RadgridView control. I have two separate RadGridView control (master-detail). Namely, when the master table is positioned on the record that has no children, the detail still shows data from previous records.
    I use VS2010 RC and Trial Teleric controls for WPF.
    Operating system: Windows 7 Ultimate Edition
  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 03 Mar 2010 Link to this post

    Hello Nebojsa Danilovic,

    Could you please give us more information about your application? It is hard to determine what the problem is by looking at the current information. It will be great if you could send us your application. 

    Here are some questions that will help us determine the problem: What kind of data are the two grid bound to? How is the details grid populated with data? 


    Kind regards,
    Milan
    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Nebojsa Danilovic
    Nebojsa Danilovic avatar
    18 posts
    Member since:
    Feb 2010

    Posted 03 Mar 2010 Link to this post

    Hi Milan,
    Thanks for the fast response. Here are some more detailed explanation:
    I use the Entity Framework with SQL 2008 Express database.
    the first table: SchoolTypes (SchoolTypeID, SchoolTypeName, PK: SchoolTypeId)
    second table: Schools (SchoolID, SchoolName, SchoolTypeID (foreign key) PK: SchoolID, FC: SchoolTypeID
    On the screen I have 2 RadGridView controls whose Itemsources are bound to corresponding CollectionViewSource (classical master-detail scenario).
    The problem is as follows:
    When the individual record from the master table(SchoolType) has child records in detail table (Schools), everything works properly, ie. second controls is showing appropriate records. The problem arises when record from the first table does not have appropriate children's records. In this case, second control, instead of being empty, it shows data related to the previous record that was selected in the first control.
    Here's the XAML:
    <Window x:Class="DSBag.w_telerik" 
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
            Title="w_telerik" Height="550" Width="529" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:my="clr-namespace:DSBag" Loaded="Window_Loaded"
        <Window.Resources> 
            <CollectionViewSource x:Key="schoolTypesViewSource" d:DesignSource="{d:DesignInstance my:SchoolType, CreateList=True}" /> 
            <CollectionViewSource x:Key="schoolTypesSchoolsViewSource" Source="{Binding Path=Schools, Source={StaticResource schoolTypesViewSource}}" /> 
        </Window.Resources> 
        <Grid DataContext="{StaticResource schoolTypesViewSource}"
            <telerik:RadGridView Height="153" HorizontalAlignment="Left" ItemsSource="{Binding}" Margin="12,12,0,0" Name="schoolTypesRadGridView" VerticalAlignment="Top" Width="482" /> 
            <telerik:RadGridView Height="268" HorizontalAlignment="Left" ItemsSource="{Binding Source={StaticResource schoolTypesSchoolsViewSource}}" Margin="12,216,0,0" Name="schoolsRadGridView" VerticalAlignment="Top" Width="482" /> 
        </Grid> 
    </Window> 

    and code that is automatically generated code behind file.
    private System.Data.Objects.ObjectQuery<SchoolType> GetSchoolTypesQuery(DSEntities dSEntities) 
            { 
                // Auto generated code 
     
                System.Data.Objects.ObjectQuery<DSBag.SchoolType> schoolTypesQuery = dSEntities.SchoolTypes; 
                // Update the query to include Schools data in SchoolTypes. You can modify this code as needed. 
                schoolTypesQuery = schoolTypesQuery.Include("Schools"); 
                // Returns an ObjectQuery. 
                return schoolTypesQuery; 
            } 
     
            private void Window_Loaded(object sender, RoutedEventArgs e) 
            { 
     
                DSBag.DSEntities dSEntities = new DSBag.DSEntities(); 
                // Load data into SchoolTypes. You can modify this code as needed. 
                System.Windows.Data.CollectionViewSource schoolTypesViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("schoolTypesViewSource"))); 
                System.Data.Objects.ObjectQuery<DSBag.SchoolType> schoolTypesQuery = this.GetSchoolTypesQuery(dSEntities); 
                schoolTypesViewSource.Source = schoolTypesQuery.Execute(System.Data.Objects.MergeOption.AppendOnly); 
            } 

    Kind Regards
    Nebojsa Danilovic
  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 09 Mar 2010 Link to this post

    Hi Nebojsa Danilovic,

    I have investigated the problem and it turned out that there is a bug in RadGridView that is manifested when RadGridView is bound to an empty ICollectionView. We have logged the issue as PITS item and you will be able to track the status of this bug.

    For the time being I can offer you a workaround that fixes the issue - it is not as elegant as the original code but it should work.

    private void Window_Loaded(object sender, RoutedEventArgs e) 
            
       
                DSBag.DSEntities dSEntities = new DSBag.DSEntities(); 
                // Load data into SchoolTypes. You can modify this code as needed. 
                System.Windows.Data.CollectionViewSource schoolTypesViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("schoolTypesViewSource"))); 
                System.Data.Objects.ObjectQuery<DSBag.SchoolType> schoolTypesQuery = this.GetSchoolTypesQuery(dSEntities); 
                schoolTypesViewSource.Source = schoolTypesQuery.Execute(System.Data.Objects.MergeOption.AppendOnly); 
      
                // CHANGE
                // subscribe to CurrentChanged
                schoolTypesViewSource.View.CurrentChanged += new System.EventHandler(View_CurrentChanged);
            
      
    void View_CurrentChanged(object sender, System.EventArgs e)
    {
        var schoolTypesViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("schoolTypesViewSource"))); 
      
        if(schoolTypesViewSource != null && schoolTypesViewSource.View != null
        {
            // get the current item of master grid
            var current = (SchoolTypes)schoolTypesViewSource.View.CurrentItem;
      
            if (current == null || current.Schools.Count <= 0)
                // clear child grid if no schools are associated 
                this.schoolsRadGridView.ItemsSource = null;
            else
                this.schoolsRadGridView.ItemsSource = current.Schools;
        }
    }

    Also you should remove the ItemsSource binding for schooldRadGridView that is defined in XAML. Finally, you should set IsSynchronizedWithCurrentItem to true for schoolTypesRadGridView. IsSynchronizedWithCurrentItem was introduced a couple of weeks ago and is available in our latest Internal Build.

    Thank you for reporting this issue - I have updated your Telerik points. We will try to fix the related bug as soon as possible. Sorry for the inconvenience.

    Greetings,
    Milan
    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.
  6. Nebojsa Danilovic
    Nebojsa Danilovic avatar
    18 posts
    Member since:
    Feb 2010

    Posted 15 Mar 2010 Link to this post

    Thanks a lot, Milan
    I will use this code.
    Best Regards
    Nebojsa
Back to Top
UI for WPF is Visual Studio 2017 Ready