Telerik blogs

I’ve made small example on how to load on demand RadGridView hierarchy child data using MVVM and RIA service: 

   Untitled

Using partial classes you can extend very easily generated code with desired load on demand logic:

    public partial class Customer
    {
        bool ordersLoaded = false;
        public IEnumerable<Order> CustomerOrders
        {
            get
            {
                if (!ordersLoaded)
                {
                    var query = from o in MyDataContext.DomainContext.GetOrdersQuery()
                                where o.CustomerID == CustomerID
                                select o;
 MyDataContext.DomainContext.Load(query);

                    ordersLoaded = true;
                }

                return Orders;
            }
        }
    }

and if you create your own data context you can bind all these completely codeless:

<telerik:RadGridView Name="RadGridView1" IsReadOnly="True" AutoGenerateColumns="False" ItemsSource="{Binding Customers}">
    <telerik:RadGridView.ChildTableDefinitions>
        <telerik:GridViewTableDefinition />
    </telerik:RadGridView.ChildTableDefinitions>
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="Customer ID" DataMemberBinding="{Binding CustomerID}" />
        <telerik:GridViewDataColumn Header="Company Name" DataMemberBinding="{Binding CompanyName}" />
        <telerik:GridViewDataColumn Header="Contact Name" DataMemberBinding="{Binding ContactName}" />
        <telerik:GridViewDataColumn Header="City" DataMemberBinding="{Binding City}" />
        <telerik:GridViewDataColumn Header="Country" DataMemberBinding="{Binding Country}" />
    </telerik:RadGridView.Columns>
    <telerik:RadGridView.HierarchyChildTemplate>
        <DataTemplate>
            <telerik:RadGridView IsReadOnly="True" AutoGenerateColumns="False" ItemsSource="{Binding CustomerOrders}">
                <telerik:RadGridView.ChildTableDefinitions>
                    <telerik:GridViewTableDefinition />
                </telerik:RadGridView.ChildTableDefinitions>
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Header="Order ID" DataMemberBinding="{Binding OrderID}" />
                    <telerik:GridViewDataColumn Header="Order Date" DataMemberBinding="{Binding OrderDate}" />
                </telerik:RadGridView.Columns>
                <telerik:RadGridView.HierarchyChildTemplate>
                    <DataTemplate>
                        <telerik:RadGridView IsReadOnly="True" AutoGenerateColumns="False" ItemsSource="{Binding Details}">
                            <telerik:RadGridView.Columns>
                                <telerik:GridViewDataColumn Header="Unit Price" DataMemberBinding="{Binding UnitPrice}" />
                                <telerik:GridViewDataColumn Header="Quantity" DataMemberBinding="{Binding Quantity}" />
                                <telerik:GridViewDataColumn Header="Discount" DataMemberBinding="{Binding Discount}" />
                            </telerik:RadGridView.Columns>
                        </telerik:RadGridView>
                    </DataTemplate>
                </telerik:RadGridView.HierarchyChildTemplate>
            </telerik:RadGridView>
        </DataTemplate>
    </telerik:RadGridView.HierarchyChildTemplate>
</telerik:RadGridView>

Enjoy!

[Download]


About the Author

Vladimir Enchev

is Director of Engineering, Native Mobile UI & Frameworks

Comments

Comments are disabled in preview mode.