Specified argument was out of the range of valid values. Parameter name: childIndex

2 posts, 0 answers
  1. Vuyiswa Maseko
    Vuyiswa Maseko avatar
    187 posts
    Member since:
    Jan 2010

    Posted 24 May 2011 Link to this post

    Good Day

    i am using the telerik Report , i am trying to load the Report on page load in Silverlight. this used to work perfectly in a Silverlight Page, now i am using  the report in a SilverlightChild Window and whenever my code reaches this pl
    var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(reportViewer, 0);

    it fails with the Error

    Specified argument was out of the range of valid values. Parameter name: childIndex


    so to make sure that it does not find the elements i used the code like this

    if (VisualTreeHelper.GetChildrenCount(reportViewer) > 0)
                {
                    var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(reportViewer, 0);
                    var viewerModel = (ReportViewerModel)layoutRoot.DataContext;
                    var refreshCommand = viewerModel.RefreshReportCommand;
                    if (refreshCommand.CanExecute(null))
                    {
                        refreshCommand.Execute(null);
                    }
                }


    I see it does not find an element.

    Thanks
  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 27 May 2011 Link to this post

    Hello Vuyiswa,

    As explained in one of your other threads, this could happen if the report viewer template has not yet been created (e.g. invoking the extension method in the window/user control constructor). To make sure the template is available use OnApplyTemplate e.g.:
    Copy Code
    public partial class MainPage : UserControl
       {
           public MainPage()
           {
               InitializeComponent();
           }
     
           public override void OnApplyTemplate()
           {
               base.OnApplyTemplate();
               this.ReportViewer1.RefreshReport();
           }
       }
     
       static class ReportViewerExtensions
       {
           public static void RefreshReport(this ReportViewer reportViewer)
           {
               var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(reportViewer, 0);
               var viewerModel = (ReportViewerModel)layoutRoot.DataContext;
               var refreshCommand = viewerModel.RefreshReportCommand;
               if (refreshCommand.CanExecute(null))
               {
                   refreshCommand.Execute(null);
               }
           }
       }

    All the best,
    Steve
    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. DevCraft banner
Back to Top