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

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

1 Answer 110 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vuyiswa
Top achievements
Rank 2
Vuyiswa asked on 24 May 2011, 10:14 AM
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

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 27 May 2011, 08:25 AM
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
Tags
General Discussions
Asked by
Vuyiswa
Top achievements
Rank 2
Answers by
Steve
Telerik team
Share this question
or