LoadOnDemad via WCF Not Loading

2 posts, 0 answers
  1. Joe
    Joe avatar
    4 posts
    Member since:
    Jun 2011

    Posted 20 Jul 2011 Link to this post

    All,

        New customer evaluating controls and I have a problem getting the RadTreeView to Load on Demand.  I tried following the examples in the Help section and follow some of the tips from the forums with no luck.

        I have a RadTreeView which should load on demand by making calls to a WCF service, debugging the app the calls are made properly and data is returned.  

        When clicking on a Node to select and then expanding the node by clicking the little arrow the TreeView will load properly.  But when just trying to click on the error to expand the node, the call to the service is made and data is returned, BUT the Ajax indicator is displayed and just sits there and spins and no nodes are ever added to the grid.

        Any help would be greatly appreciated.  Here is the XAML: 

    <UserControl x:Class="SilverLightRemitFlow.MainPage"
            xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices" 
            xmlns:telerikQuickStart="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls"
            mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="600" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
          
        <UserControl.Resources>
            <DataTemplate x:Key="OrdersTemplate">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="OrderID : " />
                    <TextBlock Text="{Binding OrderID}" />
                </StackPanel>
            </DataTemplate>
            <telerik:HierarchicalDataTemplate x:Key="tplPayers" ItemsSource="{Binding XXX}" ItemTemplate="{StaticResource OrdersTemplate}">
                <TextBlock Text="{Binding PayerName}" />
            </telerik:HierarchicalDataTemplate>
            <telerik:HierarchicalDataTemplate x:Key="tplFacilities" ItemsSource="{Binding PayerNode}" ItemTemplate="{StaticResource tplPayers}">
                <TextBlock Text="{Binding FacilityName}" />
            </telerik:HierarchicalDataTemplate>
            <telerik:HierarchicalDataTemplate x:Key="tplHospitalSystem" ItemsSource="{Binding Facility}" ItemTemplate="{StaticResource tplFacilities}"  >
                <TextBlock Text="{Binding SystemName}" />
            </telerik:HierarchicalDataTemplate>
        </UserControl.Resources>
      
        <Grid x:Name="LayoutRoot">
            <Grid.RowDefinitions>
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <sdk:GridSplitter x:Name="grsplSplitter" Grid.Row="0" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Center" Background="Aqua" Width="5">
            </sdk:GridSplitter>
            <TextBlock Text="Load on Demand" Margin="8"/>
            <telerik:RadTreeView Height="554" HorizontalAlignment="Left" Margin="12,34,0,0" Name="radTree" VerticalAlignment="Top" Width="314" Background="Gainsboro"
                                 IsLoadOnDemandEnabled="True" IsExpandOnSingleClickEnabled="False" ItemTemplate="{StaticResource tplHospitalSystem}"
                                 ItemClick="radTree_LoadOnDemand" Expanded="radTree_Expanded">
            </telerik:RadTreeView>
        </Grid>
      
    </UserControl>

    And The Code Behind:
    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 SilverLightRemitFlow.RemitFlow.WebServiceSite;
    using Telerik.Windows.Controls;
    using System.Collections.ObjectModel;
      
    namespace SilverLightRemitFlow {
        public partial class MainPage : UserControl {
      
            public MainPage() {
                InitializeComponent();
      
                this.radTree.LoadOnDemand += new EventHandler<Telerik.Windows.RadRoutedEventArgs>(radTree_LoadOnDemand);
                this.radTree.ItemPrepared += new EventHandler<RadTreeViewItemPreparedEventArgs>(radTree_ItemPrepared);
      
                Loaded += MainPage_Loaded;
            }
      
            public void MainPage_Loaded(object sender, RoutedEventArgs e) {
                BeginLoadingHospitals("2");
      
            }
      
            public void radTree_ItemPrepared(object sender, RadTreeViewItemPreparedEventArgs e) {
                RadTreeViewItem item = e.PreparedItem;
                if (item.Item is EobDetail) {
                    //item.IsLoadOnDemandEnabled = false;
                }
            }
      
            private RadTreeViewItem currentItem;
            public void radTree_LoadOnDemand(object sender, Telerik.Windows.RadRoutedEventArgs e) {
      
                RadTreeViewItem item = e.OriginalSource as RadTreeViewItem;
                currentItem = item;
      
                HospitalSystem h = currentItem.Item as HospitalSystem;
                if (h != null) {
                    BeginLoadingFacilities("2");
      
                } else {
                    Facility f = currentItem.Item as Facility;
                    if (f != null) {
                        BeginLoadingPayers("7");
                    } else {
                      
                    }
                }
            }
      
            private void radTree_Expanded(object sender, Telerik.Windows.RadRoutedEventArgs e) { }
      
            public void BeginLoadingHospitals(string SystemId) {
                RemitFlowClient proxy = new RemitFlowClient("basic");
                proxy.GetHospitalSystemsCompleted += new EventHandler<GetHospitalSystemsCompletedEventArgs>(GetHospitalSystemsCompleted);
                proxy.GetHospitalSystemsAsync(SystemId);
            }
      
            private void GetHospitalSystemsCompleted(object sender, GetHospitalSystemsCompletedEventArgs e) {
                try {
                    if (e.Error == null && e.Result != null) {
                        List<HospitalSystem> hNodes = new List<HospitalSystem>();
                        hNodes = e.Result;
                        this.radTree.ItemsSource = hNodes;
                    }
                } catch {
      
                }
            }
      
            public void BeginLoadingFacilities(string SystemId) {
                RemitFlowClient proxy = new RemitFlowClient("basic");
                proxy.GetFacilitiesCompleted += new EventHandler<GetFacilitiesCompletedEventArgs>(GetFacilitiesCompleted);
                proxy.GetFacilitiesAsync(SystemId);
            }
      
            private void GetFacilitiesCompleted(object sender, GetFacilitiesCompletedEventArgs e) {
                try {
                    if (e.Error == null && e.Result != null) {
                          
                        List<Facility> fNodes = new List<Facility>();
                        fNodes = e.Result;
      
                        foreach (Facility facility in fNodes) {
                            RadTreeViewItem newItem = new RadTreeViewItem() {
                                Header = facility.FacilityName,
                                Tag = facility.FacilityId
                            };
                          
                              
                            /* ** THIS WILL WORK, But then I can't use the Item Templates!! ** */
                            //    currentItem.Items.Add(newItem);
      
                        }
      
                        currentItem.ItemsSource = fNodes;
                        //currentItem.Items.Add(fNodes);
      
                    }
                } catch {
      
                }
            }
      
            public void BeginLoadingPayers(string FacilityId) {
                RemitFlowClient proxy = new RemitFlowClient("basic");
                proxy.GetDistinctPayersCompleted += new EventHandler<GetDistinctPayersCompletedEventArgs>(GetPayersCompleted);
                proxy.GetDistinctPayersAsync(FacilityId);
            }
      
            private void GetPayersCompleted(object sender, GetDistinctPayersCompletedEventArgs e) {
                try {
                    if (e.Error == null && e.Result != null) {
      
                        List<PayerNode> pNodes = new List<PayerNode>();
                        pNodes = e.Result;
      
                        foreach (PayerNode payer in pNodes) {
                            RadTreeViewItem newItem = new RadTreeViewItem() {
                                Header = payer.PayerName,
                                Tag = payer.PayerId
                            };
                            /* ** THIS WILL WORK, But then I can't use the Item Templates!! ** */
                            //    currentItem.Items.Add(newItem);
      
                        }
      
                        currentItem.ItemsSource = pNodes;
                        //currentItem.Items.Add(pNodes);
      
                    }
                } catch {
      
                }
            }
        }
    }

  2. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1511 posts

    Posted 25 Jul 2011 Link to this post

    Hello Joe,

    Unfortunately there are a lot of missing pieces from the code you provided us with and I am unable to reproduce the issue. I've created a simple application demonstrating the proper usage of the LoadOnDemand feature. Please have a look at it and let me know if you manage to reproduce your issue with it. I'll be glad to further assist you.

    All the best,
    Kiril Stanoev
    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!

  3. DevCraft banner
Back to Top