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

Exporting PagedData - PageIndex cannot be negative when PageSize is positive

7 Answers 167 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jill
Top achievements
Rank 1
Jill asked on 09 Feb 2011, 06:37 PM
Hi all,

I am using RadDataPager and GridView to export data spans multiple pages. I followed the demo here:
http://demos.telerik.com/silverlight/#GridView/ExportingPagedData

No errors are reported in Visual Studio. I compile and run the application, and click on my "export" button - at the prompt, I enter a file name for the .xls and hit "save." Then I get the following error:
                            An unhandled exception ("Unhandled Error in Silverlight Application
                            Code: 4004
                            Category: ManagedRuntimeError
                            Message: System.ArgumentOutOfRangeException: PageIndex cannot be negative when PageSize is positive.
Where would the PageIndex set to a negative number? I'm overlooking something obvious - a value I should have set somewhere or something - but I can't find it. I followed the demo closely and it seemed to be working for me until I tried to export the file.

Any ideas? I'm using Telerik Reporting Q3 and Visual Studio 2010. Thanks!

7 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 10 Feb 2011, 02:34 PM
Hi Jill,

This is strange. Please find attached a sample project and see if it works for you.

All the best,
Veselin Vasilev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Jill
Top achievements
Rank 1
answered on 11 Feb 2011, 08:14 PM
The demo sample project worked, but my project still doesn't. I don't know where the "PageIndex" was set or how it could be negative - I actually have something like 15 pages of data. I'm definately stumped, especially since Visual Studio doesn't fine any errors or warnings. I can click on my export button, window opens, I enter a filename, and click "Save" - that's when I get the runtime error. Everything else seems to work fine.

Here is the full error:

Microsoft JScript runtime error: Unhandled Error in Silverlight Application
Code: 4004   
Category: ManagedRuntimeError      
Message: System.ArgumentOutOfRangeException: PageIndex cannot be negative when PageSize is positive.
Parameter name: newPageIndex
   at Telerik.Windows.Controls.RadDataPager.CheckPageIndexChange(Int32 oldPageIndex, Int32 newPageIndex)
   at Telerik.Windows.Controls.RadDataPager.OnPageIndexPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
   at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at Telerik.Windows.Controls.RadDataPager.set_PageIndex(Int32 value)
   at Telerik.Windows.Controls.RadDataPager.UpdatePageIndex()
   at Telerik.Windows.Controls.RadDataPager.OnViewModelPropertyChanged(Object sender, PropertyChangedEventArgs e)
   at Telerik.Windows.Controls.Data.DataPager.DataPagerViewModel.Telerik.Windows.Data.IWeakEventListener<System.ComponentModel.PropertyChangedEventArgs>.ReceiveWeakEvent(Object sender, PropertyChangedEventArgs args)
   at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
   at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
   at Telerik.Windows.Data.DataItemCollection.OnPropertyChanged(PropertyChangedEventArgs e)
   at Telerik.Windows.Data.DataItemCollection.Telerik.Windows.Data.IWeakEventListener<System.ComponentModel.PropertyChangedEventArgs>.ReceiveWeakEvent(Object sender, PropertyChangedEventArgs args)
   at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
   at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
   at Telerik.Windows.Data.QueryableCollectionView.OnPropertyChanged(PropertyChangedEventArgs e)
   at Telerik.Windows.Data.QueryableDomainServiceCollectionViewBase.OnPropertyChanged(PropertyChangedEventArgs e)
   at Telerik.Windows.Data.QueryableCollectionView.OnPropertyChanged(String propertyName)
   at Telerik.Windows.Data.QueryableCollectionView.set_PageIndex(Int32 value)
   at Telerik.Windows.Data.QueryableDomainServiceCollectionView`1.OnDomainServiceCollectionLoadCompleted(Object sender, LoadOperationCompletedEventArgs`1 e)
   at Telerik.Windows.Controls.DomainServices.DomainServiceCollection`1.OnLoadCompleted(LoadOperationCompletedEventArgs`1 args)
   at Telerik.Windows.Controls.DomainServices.DomainServiceCollection`1.OnLoadOperationCompleted(LoadOperation`1 loadOperation)
   at System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass13`1.<Load>b__11(LoadOperation lo)
   at System.ServiceModel.DomainServices.Client.LoadOperation.<>c__DisplayClass4`1.<Create>b__0(LoadOperation`1 arg)
   at System.ServiceModel.DomainServices.Client.LoadOperation`1.InvokeCompleteAction()
   at System.ServiceModel.DomainServices.Client.OperationBase.Complete(Object result)
   at System.ServiceModel.DomainServices.Client.LoadOperation.Complete(DomainClientResult result)
   at System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
   at System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )    
0
Jill
Top achievements
Rank 1
answered on 14 Feb 2011, 08:52 PM
Here is the C# code for my 'export all' button. As stated above, I get no errors in VS and everything seems to be working fine until I click on the button and try to save the file.

 
private void ExportAllButtonClick(object sender, RoutedEventArgs e)
{
    string extension = "xls";
    SaveFileDialog dialog = new SaveFileDialog()
    {
     DefaultExt = extension,
     Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),
     FilterIndex = 1
    };
    if (dialog.ShowDialog() == true)
    {
        int originalPageSize = Pager.PageSize;
        int originalPageIndex = Pager.PageIndex;
        using (Stream stream = dialog.OpenFile())
        {
            Pager.PageSize = 0;
            ProductsGrid.Export(stream,
             new GridViewExportOptions()
             {
                 Format = ExportFormat.Html,
                 ShowColumnHeaders = true,
                 ShowColumnFooters = true,
                 ShowGroupFooters = false,
             });
        }
        Pager.PageSize = originalPageSize;
        Pager.PageIndex = originalPageIndex;
    }
}

 

0
Accepted
Yordanka
Telerik team
answered on 17 Feb 2011, 08:53 AM
Hello Jill,

Please, excuse us for the late reply.

We have tried to reproduce the exception but everything works as expected on our side. We may suggest you to try our latest internal build - version .1414 and check if the problem still appears. If so, could you try to reproduce your case by modifying Veselin Vasilev's sample project ? Any additional details will be plus.

We are looking forward to hearing from you.
 
Greetings,
Yordanka
the Telerik team
0
Nick
Top achievements
Rank 1
answered on 23 Nov 2011, 04:19 PM
Jill,

Did you ever figure out a solution.  I am having the same exact issue with same code.

Can someone help?

Thanks,
Jorge
0
Technique
Top achievements
Rank 1
answered on 19 Mar 2014, 01:31 PM
2014, I also have this error, the DataPager seems a little erratic...

Sometimes I have this:
System.ArgumentOutOfRangeException: PageIndex cannot be negative when PageSize is positive.

Some other times I have this :
System.ArgumentOutOfRangeException: pageindex can only be set to -1 when the pagesize is 0


0
Hristo
Telerik team
answered on 21 Mar 2014, 04:36 PM
Hello Jillian,

I tried to reproduce this issue, however everything works fine on my side. I am attaching a sample project demonstrating the approach, with the current version of our controls (Q1 2014). Can you see and modify ti so that it results in the exception you reported ?

Regards,
Hristo
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
GridView
Asked by
Jill
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Jill
Top achievements
Rank 1
Yordanka
Telerik team
Nick
Top achievements
Rank 1
Technique
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or