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

Navigating from one view to another getting error:PageIndex cannot be negative when PageSize is positive. Parameter name: newPageIndex

6 Answers 63 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 17 Oct 2013, 04:32 PM
I have a WPF MVVM application that uses a ContentControl on my main window to display views(UserControls). My first view has a RadGridView and a RadDataPager in it. When I try to navigate to another view I get the error: PageIndex cannot be negative when PageSize is positive. Parameter name: newPageIndex. I have commented out the RadDataPager to verify that it is part of the issue...and it is.
I believe it has something to do with the Binding. I do NOT  set the PageIndex to -1 in the code.

I have included a LINK to a small sample project that repeats the issue. Can someone please tell me how to fix this.

<telerik:RadGridView x:Name="RgvPatients"
    HorizontalAlignment="Stretch" VerticalAlignment="Top" HorizontalContentAlignment="Center"
    AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single" SelectionUnit="Cell"
    ShowGroupPanel="False" EnableRowVirtualization="False" RowIndicatorVisibility="Collapsed"
    IsFilteringAllowed="False" ItemsSource="{Binding Patients}" GridLinesVisibility="Horizontal" >
    <telerik:RadGridView.Columns>
        <telerik:GridViewColumn Header="MRN#" IsSortable="True">
            <telerik:GridViewColumn.CellTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Button Style="{StaticResource ButtonTransparentBlackText}" VerticalAlignment="Center" Height="25" Width="100"
                             Command="{Binding Path=SelectPatientCommand}" Content="{Binding mrn}">
                        </Button>
                    </Grid>
                </DataTemplate>
            </telerik:GridViewColumn.CellTemplate>
        </telerik:GridViewColumn>
        <telerik:GridViewDataColumn Header="Last Name"  DataMemberBinding="{Binding last_name}" IsReadOnly="True" TextAlignment="Left" />
        <telerik:GridViewDataColumn Header="First Name"  DataMemberBinding="{Binding first_name}" IsReadOnly="True" TextAlignment="Left" />
        <telerik:GridViewDataColumn Header="Middle Name"  DataMemberBinding="{Binding middle_name}" IsReadOnly="True" TextAlignment="Left" />
        <telerik:GridViewDataColumn Header="DOB"  DataMemberBinding="{Binding dob, StringFormat='{}{0:MM/dd/yyyy}'}" IsReadOnly="True" TextAlignment="Left" />
        <telerik:GridViewDataColumn Header="Age"  DataMemberBinding="{Binding dob, Converter={StaticResource AgeConverter}}"  IsReadOnly="True" TextAlignment="Left" />
        <telerik:GridViewDataColumn Header="Gender"  DataMemberBinding="{Binding Gender}" IsReadOnly="True" TextAlignment="Left" />
        <telerik:GridViewDataColumn Header="Status"  DataMemberBinding="{Binding adt_type}" IsReadOnly="True" TextAlignment="Left" />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>
<DockPanel>
    <telerik:RadDataPager x:Name="RdpPatients" DockPanel.Dock="Left" Width="830" NumericButtonCount="5" Height="28" DisplayMode="All" 
           PageIndex="{Binding Path=PageData.PageIndex, Mode=TwoWay}"
           PageSize="20"
            
           ItemCount="{Binding Path=PageData.TotalRecords}" >
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="PageIndexChanged">
                <i:InvokeCommandAction Command="{Binding RdpPatients_PageIndexChangedCommand}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </telerik:RadDataPager>
</DockPanel>

Thanks ~Doug

6 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 23 Oct 2013, 07:48 AM
Hi,

I run your project but I were not able to reproduce the error.
You say that it is raised when you try to navigate to another view. Would you please guide me how I can do this? What are the exact steps I need to perform?

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Doug
Top achievements
Rank 1
answered on 30 Oct 2013, 01:30 PM
Didie,

Thank you for replying.
Here are the steps I do to get the error:
  1. Start application in debug mode from VS2012
  2. Click the Patient Home Page link just above the grid on the left side of the window.
  3. The Argument out of range exception of PageIndex cannot be negative when PageSize is positive occurs

0
Dimitrina
Telerik team
answered on 01 Nov 2013, 02:37 PM
Hello,

I built the project in Debug mode and I followed your instructions. You can review the result I got on this video.

Do you get different result if you build in Release? The attached solution has references to version Q3 2012, would you please also test with out latest assemblies - Q3 2013?

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Doug
Top achievements
Rank 1
answered on 05 Nov 2013, 02:09 PM
Didie,

Sorry I knew I should have removed the menu control from the screen. The Patient Home Page link I have code attached to is the one just above the grid as in the one that the mouse is pointing to in the attached image(Nothing else is wired up).
We have not yet moved to the 2013 Q3 release. But if you think that will solve this problem then I can make a case for upgrading.

I have been doing some work on this and found that it has something to do with the Binding mode being TwoWay:
<telerik:RadDataPager x:Name="RdpPatients" DockPanel.Dock="Left" Width="830" NumericButtonCount="5" Height="28" DisplayMode="All" 
PageIndex="{Binding Path=PageData.PageIndex, Mode=TwoWay}"
PageSize="20"

When I change it to OneWay it does not crash...But I need it to be TwoWay.

Thanks ~Doug
0
Yordanka
Telerik team
answered on 08 Nov 2013, 01:43 PM
Hi Doug,

Thank you for the details.

I was able to reproduce the error and will log it for further investigation. i will contact you as soon as I have more information.
 
Regards,
Yordanka
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Nick
Telerik team
answered on 15 Nov 2013, 09:38 AM
Hi Doug,

Thank you for your patience! 

After some investigations, the problem is that the Pager gets in an invalid state. 

You need to reset the whole pager(page size and index), when you change the views, since the static page size remains 20 while the pageindex gets to -1, leading to the exception.

Hope this helps! 

Regards,
Nik
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Doug
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Doug
Top achievements
Rank 1
Yordanka
Telerik team
Nick
Telerik team
Share this question
or