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

Unable to add column names to child/parent template in Hier. Grid

12 Answers 208 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 22 Mar 2011, 09:22 PM
Hi,

I am getting an error throw when I try to add the column names to the child and parent relations in a hierarchical gridview.  I am using your WINForms sample, except that I changed the datasource to Entity Framework 4 .edmx, and am using .Net 4.0 on a WIN7 OS.  I've attached 2 files, 'Form1' shows the results.  All works fine, except the child grids are not linked to the ContactID on the grid (the relationships are defines properly in the .edmx).  'Relations' shows the results I'm getting when I try to set them in the properties window.

Thanks

Steve

12 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 25 Mar 2011, 11:23 AM
Hello Steve,

Could you please provide a small example where you can illustrate this behavior?

So that we can try to find a solution on that example.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Steve
Top achievements
Rank 1
answered on 25 Mar 2011, 03:29 PM
How do I attach the solution without losing this thread?  The only attachments allowed are .jpegs, etc., whereas the solution is .zip.
0
Steve
Top achievements
Rank 1
answered on 25 Mar 2011, 04:25 PM
Emanuel,
I have uploaded the file already on another thread, with Nikolay.  The thread ID is 405063.  Is it possible for you to get it via that location?
0
Emanuel Varga
Top achievements
Rank 1
answered on 25 Mar 2011, 04:27 PM
Hello again Steve,

Do you mean a ticket id?

Sadly i do not have access to the support / tickets. If you could upload it somewhere else i will do my best to help you.

Best Regards,
Emanuel Varga
Telerik WinForms MVP 
0
Steve
Top achievements
Rank 1
answered on 25 Mar 2011, 04:31 PM
Where can I do that?  Can I e-mail it to you, or is there another place to upload it on your site?
0
Emanuel Varga
Top achievements
Rank 1
answered on 26 Mar 2011, 05:46 PM
Hello again Steve,

Please excuse me for the delay. Couldn't you please upload your sample project to one of the file sharing sites out there?
Or if you want you can copy all of your files here in different code blocks that would be ok also.

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Steve
Top achievements
Rank 1
answered on 28 Mar 2011, 05:19 PM
here is the XAML:
<Examples:GridViewExample x:Class="TestRadWPFApp.GridViewSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Examples="clr-namespace:TestRadWPFApp"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    xmlns:Northwind="clr-namespace:NorthwindData;assembly=NorthwindData"
	xmlns:telerikQuickStart="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls">
    <Grid>
        <Border telerikQuickStart:ThemeAwareBackgroundBehavior.IsEnabled="True" />
        <telerik:RadGridView x:Name="RadGridView1" CanUserFreezeColumns="False" GridLinesVisibility="Horizontal" ItemsSource="{Binding Order}"  IsReadOnly="True" AutoGenerateColumns="False">
            <telerik:RadGridView.ChildTableDefinitions>
                <telerik:GridViewTableDefinition />
            </telerik:RadGridView.ChildTableDefinitions>
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding OrderDate}" Header="Order Date" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Employee.LastName}" Header="Employee" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Freight}" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding ShipCountry}" Header="Ship Country" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding ShipCity}" Header="Ship City" />
            </telerik:RadGridView.Columns>
            <telerik:RadGridView.HierarchyChildTemplate>
                <DataTemplate>
                    <telerik:RadGridView x:Name="RadGridView1" CanUserFreezeColumns="False" AutoGenerateColumns="False" ItemsSource="{Binding Order_Detail}"  ShowGroupPanel="False" IsReadOnly="True">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding ProductID}" Header="Product ID" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding UnitPrice}" DataFormatString="{}{0:c}" Header="Unit Price" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Quantity}" Header="Quantity" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Discount}" Header="Discount" />
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>
                </DataTemplate>
            </telerik:RadGridView.HierarchyChildTemplate>
        </telerik:RadGridView>
    </Grid>
</Examples:GridViewExample>

It's Code behind:
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using Telerik.Windows.Data;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using NorthwindData;
 
namespace TestRadWPFApp
{
    /// <summary>
    /// Interaction logic for GridViewSample.xaml
    /// </summary>
    public partial class GridViewSample
    {// example of Hierarchy Child Template
        public GridViewSample()
        {
            
            InitializeComponent();
            
        }
 
    }
}
 The second XAML:
<Examples:GridViewExample x:Class="TestRadWPFApp.GridViewSample2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Examples="clr-namespace:TestRadWPFApp"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    xmlns:telerikQuickStart="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls" xmlns:TestRadWPFApp="clr-namespace:TestRadWPFApp" Loaded="GridViewExample_Loaded">
        <Grid>
            <Border telerikQuickStart:ThemeAwareBackgroundBehavior.IsEnabled="True" />
            <telerik:RadGridView x:Name="RadGridView1" CanUserFreezeColumns="False" ItemsSource="{Binding Orders}" RowLoaded="RadGridView1_RowLoaded" DataLoading="RadGridView1_DataLoading"  IsReadOnly="True" AutoGenerateColumns="False" ShowGroupPanel="False">
                <telerik:RadGridView.ChildTableDefinitions>
                    <telerik:GridViewTableDefinition>
                        <telerik:GridViewTableDefinition.Relation>
                            <telerik:PropertyRelation ParentPropertyName="Details"/>
                        </telerik:GridViewTableDefinition.Relation>
                    </telerik:GridViewTableDefinition>
                </telerik:RadGridView.ChildTableDefinitions>
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding OrderDate}" Header="Order Date" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Employee.LastName}" Header="Employee" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Freight}" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding ShipCountry}" Header="Ship Country" />
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding ShipCity}" Header="Ship City" />
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
        </Grid>
        <telerikQuickStart:QuickStart.ConfigurationPanel>
            <StackPanel Margin="3">
                <Button Click="RemoveButton_Click" Content="Remove" Margin="0,2" />
                <Button Click="RestoreButton_Click" Content="Restore" Margin="0,2" />
            </StackPanel>
        </telerikQuickStart:QuickStart.ConfigurationPanel>
</Examples:GridViewExample>

and it's Codebehind:
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.Windows;
using NorthwindData;
using Telerik.Windows.Data;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
 
namespace TestRadWPFApp
{
    /// <summary>
    /// Interaction logic for GridViewSample2.xaml
    /// </summary>
    public partial class GridViewSample2 
    {
        // example of Custom Hierarchy
        public GridViewSample2()
        {
            InitializeComponent();
        }
 
        private void RemoveButton_Click(object sender, RoutedEventArgs e)
        {
            RadGridView1.ChildTableDefinitions.Clear();
        }
 
        private void RestoreButton_Click(object sender, RoutedEventArgs e)
        {
            RadGridView1.ChildTableDefinitions.Clear();
 
            GridViewTableDefinition definition = new GridViewTableDefinition();
            definition.Relation = new PropertyRelation("Details");
            RadGridView1.ChildTableDefinitions.Add(definition);
        }
 
        private void RadGridView1_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            GridViewRow row = e.Row as GridViewRow;
            if (row != null)
            {
                Order order = row.DataContext as Order;
                if (row != null && order != null)
                {
                    row.IsExpandable = order.ShipCountry == "France" || order.ShipCountry == "Brazil";
                }
                else
                {
                    row.IsExpandable = false;
                }
            }
        }
 
        private void RadGridView1_DataLoading(object sender, GridViewDataLoadingEventArgs e)
        {
            GridViewDataControl dataControl = (GridViewDataControl) sender;
            if (dataControl.ParentRow != null)
            {
                dataControl.CanUserFreezeColumns = false;
                dataControl.ShowGroupPanel = false;
                dataControl.AutoGenerateColumns = false;
 
                GridViewDataColumn column = new GridViewDataColumn();
                column.Header = "Order ID";
                column.DataMemberBinding = new System.Windows.Data.Binding("OrderID");
                dataControl.Columns.Add(column);
 
                column = new GridViewDataColumn();
                column.Header = "Product ID";
                column.DataMemberBinding = new System.Windows.Data.Binding("ProductID");
                dataControl.Columns.Add(column);
 
                column = new GridViewDataColumn();
                column.Header = "Unit Price";
                column.DataFormatString = "{0:c}";
                column.DataMemberBinding = new System.Windows.Data.Binding("UnitPrice");
                dataControl.Columns.Add(column);
 
                column = new GridViewDataColumn();
                column.Header = "Quantity";
                column.DataMemberBinding = new System.Windows.Data.Binding("Quantity");
                dataControl.Columns.Add(column);
            }
        }
 
        private void GridViewExample_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
 
        }
    }
}

The Repository that is the DataContext: (the interface just stubs the methods)
using System;
using System.Linq;
 
namespace NorthwindData
{
    public partial class NorthwindRepository : RepositoryBase<NorthwndEntities>INorthwindRepository
    {
        public IQueryable<Order> GetOrders()
        {
            return DataContext.Orders.OrderBy(b => b.OrderDate);
        }
 
        public IQueryable<Order> GetOrder(int orderid)
        {
            return DataContext.Orders.Where(b => b.OrderID == orderid).OrderBy(b => b.OrderDate);
        }
 
        public IQueryable<Order_Detail> GetDetails(int orderid)
        {
            return DataContext.Order_Detail.Where(b => b.OrderID == orderid).OrderBy(b => b.Product);
        }
 
        public IQueryable<Order_Detail> GetDetail(int orderid, int productid)
        {
            return DataContext.Order_Detail.Where(b => b.OrderID == orderid && b.OrderID == productid).OrderBy(b => b.OrderID).OrderBy(b => b.ProductID);
        }
 
        public IQueryable<Employee> GetEmployees(int employeeid)
        {
            return DataContext.Employees.Where(b => b.EmployeeID==employeeid).OrderBy(b => b.LastName + ' ' + b.FirstName);
        }
    }
}

The Base Class for the Repository:
using System;
using System.Data.Objects;
using System.Linq;
using System.Linq.Expressions;
 
 
namespace NorthwindData
{
 
    public class RepositoryBase<C> : IDisposable
        where C : ObjectContextnew()
    {
        private C _DataContext;
 
        public virtual C DataContext
        {
            get
            {
                if (_DataContext == null)
                {
                    _DataContext = new C();
                }
                return _DataContext;
            }
        }
 
        public virtual T Get<T>(Expression<Func<T, bool>> predicate) where T : class
        {
            if (predicate != null)
            {
                using (DataContext)
                {
                    return DataContext.CreateObjectSet<T>().Where(predicate).SingleOrDefault();
                }
            }
            else
            {
                throw new ApplicationException("Predicate value must be passed to Get<T>.");
            }
        }
 
        public virtual IQueryable<T> GetList<T>(Expression<Func<T, bool>> predicate) where T : class
        {
            try
            {
                return DataContext.CreateObjectSet<T>().Where(predicate);
            }
            catch (Exception ex)
            {
                //Log error
              
            }
            return null;
        }
 
        public virtual IQueryable<T> GetList<T, TKey>(Expression<Func<T, bool>> predicate,
            Expression<Func<T, TKey>> orderBy) where T : class
        {
            try
            {
                return GetList(predicate).OrderBy(orderBy);
            }
            catch (Exception ex)
            {
                //Log error
                
            }
            return null;
        }
 
        public virtual IQueryable<T> GetList<T, TKey>(Expression<Func<T, TKey>> orderBy) where T : class
        {
            try
            {
                return GetList<T>().OrderBy(orderBy);
            }
            catch (Exception ex)
            {
                //Log error
            }
            return null;
        }
 
        public virtual IQueryable<T> GetList<T>() where T : class
        {
            try
            {
                return DataContext.CreateObjectSet<T>();
            }
            catch (Exception ex)
            {
                //Log error
            }
            return null;
        }
 
        public virtual OperationStatus Update<T>(T entity, params string[] propsToUpdate) where T : classIObjectWithChangeTracker
        {
            OperationStatus opStatus = new OperationStatus { Status = true };
 
            try
            {
                DataContext.CreateObjectSet<T>().Attach(entity);
                var entry = DataContext.ObjectStateManager.GetObjectStateEntry(entity);
                if (propsToUpdate != null)
                {
                    //Control updating specific properties
                    foreach (var propName in propsToUpdate)
                    {
                        entry.SetModifiedProperty(propName);
                    }
                }
                opStatus.Status = DataContext.SaveChanges() > 0;
            }
            catch (Exception exp)
            {
                opStatus = OperationStatus.CreateFromException("Error updating " + typeof(T) + ".", exp);
            }
 
            return opStatus;
        }
 
        public virtual OperationStatus Insert<T>(T entity) where T : classIObjectWithChangeTracker
        {
            OperationStatus opStatus = new OperationStatus { Status = true };
 
            try
            {
                ObjectSet<T> objectSet = DataContext.CreateObjectSet<T>();
                objectSet.AddObject(entity);
                opStatus.Status = DataContext.SaveChanges() > 0;
            }
            catch (Exception exp)
            {
                return OperationStatus.CreateFromException("Error inserting " + typeof(T) + ": " + exp.Message, exp);
            }
 
            return opStatus;
        }
 
        public virtual OperationStatus Delete<T>(T entity) where T : classIObjectWithChangeTracker
        {
            OperationStatus opStatus = new OperationStatus { Status = true };
 
            try
            {
                ObjectSet<T> objectSet = DataContext.CreateObjectSet<T>();
                objectSet.Attach(entity);
                objectSet.DeleteObject(entity);
                opStatus.Status = DataContext.SaveChanges() > 0;
            }
            catch (Exception exp)
            {
                return OperationStatus.CreateFromException("Error deleting " + typeof(T), exp);
            }
 
            return opStatus;
        }
 
        public OperationStatus ExecuteStoreCommand(string cmdText, params object[] parameters)
        {
            var opStatus = new OperationStatus { Status = true };
 
            try
            {
                opStatus.RecordsAffected = DataContext.ExecuteStoreCommand(cmdText, parameters);
            }
            catch (Exception exp)
            {
                OperationStatus.CreateFromException("Error executing store command: ", exp);
            }
            return opStatus;
        }
 
 
        public void Dispose()
        {
            if (DataContext != null) DataContext.Dispose();
        }
    }
}
  Here is the GridViewExample Class, almost the same as in your GridView Sample:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using NorthwindData;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.QuickStart;
 
namespace TestRadWPFApp
{
    public class GridViewExample : UserControl
    {// example of  Hierarchy Child Template
        private NorthwindRepository _northwindRepository;
        public GridViewExample()
        {
            this.DataContext = new NorthwindRepository();
 
            this.Loaded += this.OnLoaded;
            this.Unloaded += this.OnUnloaded;
        }
 
        protected virtual void OnLoaded(object sender, RoutedEventArgs e)
        {
 
        }
 
        /// <summary>
        /// Used to clear any set data context and avoid memory leaks.
        /// </summary>
        protected virtual void OnUnloaded(object sender, RoutedEventArgs e)
        {
 
        }
 
        protected Panel ConfigurationPanel
        {
            get
            {
                return QuickStart.GetConfigurationPanel(this);
            }
        }
    }
}

and the App.Xaml:
<Application x:Class="TestRadWPFApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="GridViewSample2.xaml">
    <Application.Resources>
         
    </Application.Resources>
</Application>


and also, see the attached Class Diagram for the Northwind.edmx.  I have this set up in my local SQL Server, not Sql Express

I do not know if this is the problem, but when I step through the debugger (all of the QuickStart.dlls are referenced):

Locating source for 'c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\QuickStart\ThemeAwareBackgroundBehavior.cs'. Checksum: MD5 {55 5b 4f 68 2d 4c 91 38 23 13 dc c9 2b 66 c9 b5}
The file 'c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\QuickStart\ThemeAwareBackgroundBehavior.cs' does not exist.
Looking in script documents for 'c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\QuickStart\ThemeAwareBackgroundBehavior.cs'...
Looking in the projects for 'c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\QuickStart\ThemeAwareBackgroundBehavior.cs'.
The file was not found in a project.
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\mfc\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\src\atl\'...
Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\'...
The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\QuickStart\ThemeAwareBackgroundBehavior.cs.
The debugger could not locate the source file 'c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\QuickStart\ThemeAwareBackgroundBehavior.cs'.
0
Julian Benkov
Telerik team
answered on 01 Apr 2011, 09:58 AM
Hi Steve,

You can find the answer to your question in the ticket where you have attached your project. The name of the ticket is: IDockable, DockingManager, RadAlarmFormShowingArgs not found in Samples afer update to latest WINForms version

All the best,
Julian Benkov
the Telerik team
0
Steve
Top achievements
Rank 1
answered on 01 Apr 2011, 03:13 PM
Hello Julian,

I had already looked at that reply, and it really didn't tell me anything at all.  What do I need to do to modify it to make it work?  It's really just your Telerik sample, using an EF4 datacontext.  Since I zipped up the whole solution I thought you guys could make a few changes to get it working.  Any chance of that?  Thanks.
0
Pavel Pavlov
Telerik team
answered on 06 Apr 2011, 11:40 AM
Hello Steve,

As mentioned in your ticket (405063) , the reason for you to not see your data is that you have wrong bindings - you try to bind to a property that does not exist in your DataContext.
The VS output says that there is no "orders" property in your DataContext.

Have you checked this ? 

Regards,
Pavel Pavlov
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
Steve
Top achievements
Rank 1
answered on 06 Apr 2011, 04:01 PM
I've tried it as 'orders' and 'order'; neither works.  Given the sample I sent, what changes need to be made to make this work?
0
Pavel Pavlov
Telerik team
answered on 11 Apr 2011, 04:43 PM
Hi Steve,

Please try the following :
add this property to your NorthwindRepository class:

public IQueryable Orders 

get
{
return this.GetOrders();
}
}


*Please note : This is actually a data access related problem - totally irellevant to RadGridView or any Telerik product.  And this is definitely not related to RadGridView for Winforms.

Regards,
Pavel Pavlov
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
Tags
GridView
Asked by
Steve
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Steve
Top achievements
Rank 1
Julian Benkov
Telerik team
Pavel Pavlov
Telerik team
Share this question
or