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

Different type Hierarchy

2 Answers 54 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jokerwolf
Top achievements
Rank 1
Jokerwolf asked on 16 Jul 2010, 10:52 AM
Hello,
Here is my gridview.
<UserControl x:Class="SilverlightApplication1.MainPage"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
    xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView">
    <Grid x:Name="LayoutRoot">
         
        <telerikGrid:RadGridView x:Name="RadGridView1" ItemsSource="{Binding}" AutoGenerateColumns="False">
            <telerikGrid:RadGridView.ChildTableDefinitions>
                <telerikGrid:GridViewTableDefinition/>
            </telerikGrid:RadGridView.ChildTableDefinitions>
             
            <telerikGrid:RadGridView.Columns>
                <telerikGrid:GridViewDataColumn Header="ID" DataMemberBinding="{Binding ID}"/>
                <telerikGrid:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}"/>
            </telerikGrid:RadGridView.Columns>
             
            <telerikGrid:RadGridView.HierarchyChildTemplate>
                <DataTemplate>
                    <telerikGrid:RadGridView x:Name="SubGrid" DataLoading="SubGrid_DataLoading"
                                             AutoGenerateColumns="False" ItemsSource="{Binding Items}">
                    </telerikGrid:RadGridView>
                </DataTemplate>
            </telerikGrid:RadGridView.HierarchyChildTemplate>
        </telerikGrid:RadGridView>
    </Grid>
</UserControl>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using Telerik.Windows.Controls;
using System.Collections.ObjectModel;
using Telerik.Windows.Data;
using Telerik.Windows.Controls.GridView;
 
namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
 
            DataContext = from i in Enumerable.Range(0, 10)
                          select new MyObject()
                          {
                              ID = i,
                              Name = String.Format("Name{0}", i)
                          };
        }
 
        public class MyObject
        {
            public int ID { get; set; }
            public string Name { get; set; }
 
            public IEnumerable<MyObject2> Items
            {
                get
                {
                    return from i in Enumerable.Range(0, 10)
                           select new MyObject2()
                           {
                               x = i
                           };
                }
            }
        }
 
        public class MyObject2
        {
            public int x { set; get; }
 
            public IEnumerable<MyObject2> Items
            {
                get
                {
                    return from i in Enumerable.Range(0, 10)
                           select new MyObject2()
                           {
                               x = i
                           };
                }
            }
        }
 
        private void SubGrid_DataLoading(object sender, GridViewDataLoadingEventArgs e)
        {
            var grid = (GridViewDataControl)sender;
 
            var d = new GridViewTableDefinition();
            d.Relation = new PropertyRelation("Items");
            grid.TableDefinition.ChildTableDefinitions.Add(d);
 
            grid.AutoGenerateColumns = false;
            grid.Columns.Add(new GridViewDataColumn() { DataMemberBinding = new Binding("x") });
        }
    }
}

For the firs time it is child one and then it becomes self-hierarchical. Everything is OK, but in the real programm we use WCF service and MyObject and MyObject2 are DataContracts, and we need to call a WCF service in the get-methods of the Items property.
So, I ask you for help: How could I call the WFC method or maybe there is another way to make such hierarchy.

2 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 16 Jul 2010, 03:50 PM
Hi Jokerwolf,

You should be able to call the WCF service from your WPF application.

ServiceReference1.Service1Client emp = new ServiceReference1.Service1Client();
gridView.ItemsSource = emp.GetEmployees();


You might find this blog post useful.

Do you face any specific problem?

Kind regards,
Veskoni
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
Jokerwolf
Top achievements
Rank 1
answered on 19 Jul 2010, 08:16 AM
Sorry, wasn't able to ask a proper question. Everything is OK now.
Tags
GridView
Asked by
Jokerwolf
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Jokerwolf
Top achievements
Rank 1
Share this question
or