Binding to RadDataPager.PageIndex property

18 posts, 1 answers
  1. Tomáš Čeleda
    Tomáš Čeleda avatar
    15 posts
    Member since:
    Sep 2009

    Posted 11 May 2010 Link to this post

    Hello,

    I have a problem with RadDataPager. In xaml I have:

    <telerikGrid:RadDataPager DisplayMode="All" AutoEllipsisMode="Both" x:Name="TracksResultsGridDataPager"  
    PageIndex="{Binding CurrentPage, Mode=TwoWay}" 
    PageSize="{Binding PageSize}"  
    Source="{Binding Results.ResultsList}" NumericButtonCount="10" 
    VerticalAlignment="Bottom"/> 

    all works properly without this line:
    PageIndex="{Binding CurrentPage, Mode=TwoWay}" 

    when this binding is added, the getter of CurrentPage is called and returns an integer value 0.
    But RadDataPager has thrown this exception:

    PageIndex can only be set to -1 when the Source is null or PageSize is 0.
    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.RefreshExpression(DependencyProperty dp)
       at System.Windows.Data.BindingExpression.SendDataToTarget()
       at System.Windows.Data.BindingExpression.SourceAcquired()
       at System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(Object sender, DataContextChangedEventArgs e)
       at System.Windows.Data.BindingExpression.DataContextChanged(Object sender, DataContextChangedEventArgs e)
       at System.Windows.DataContextChangedEventHandler.Invoke(Object sender, DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
       at System.Windows.FrameworkElement.OnPropertyChanged(DependencyProperty dp)
       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.FrameworkElement.set_DataContext(Object value)
       at Aitee.MusicSearch.Portal.Search.<>c__DisplayClass3.<StartNewSearchForTracks>b__2(SearchResults res)
       at Aitee.MusicSearch.SearchEngineClient.<>c__DisplayClass2.<StartReload>b__0(LoadOperation`1 c)
       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 )

    Any ideas how to solve this?
  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 12 May 2010 Link to this post

    Hello Tomáš Čeleda,

    As far as I can see the PageIndex binding sets a value of -1 to PageIndex which is not allowed when PageSize is different from 0. We enforce this rule because PageIndex of -1 is not correct value. 

    One possible solution is to have PageIndex of 0 - as a default value for CurrentPage. 

    Regards,
    Milan
    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
  4. Tomáš Čeleda
    Tomáš Čeleda avatar
    15 posts
    Member since:
    Sep 2009

    Posted 26 May 2010 Link to this post

    Hello Milan,

    thank you for your reply and sorry for my delay. The problem is that the PageIndex is 0 not -1. I set a breakpoint in getter and I have seen it clearly.

    <UserControl x:Class="pokuspaging.MainPage" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
                 xmlns:telerikPager="clr-namespace:Telerik.Windows.Controls.DataPager;assembly=Telerik.Windows.Controls.GridView" 
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">  
      <Grid x:Name="LayoutRoot">  
            <StackPanel Orientation="Vertical">  
                <telerikGrid:RadGridView x:Name="Grid1" ItemsSource="{Binding PagedSource, ElementName=Pager}"  /> 
                <telerikGrid:RadDataPager x:Name="Pager" PageIndex="{Binding PageIndex, Mode=TwoWay}" Source="{Binding Data}" PageSize="10" /> 
            </StackPanel> 
        </Grid> 
    </UserControl> 
     


     public partial class MainPage : UserControl  
        {  
            public MainPage()  
            {  
                InitializeComponent();  
     
                Loaded += new RoutedEventHandler(MainPage_Loaded);  
            }  
     
            void MainPage_Loaded(object sender, RoutedEventArgs e)  
            {  
                DataContext = new ViewModel();  
            }  
        } 

    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.ComponentModel;  
     
    namespace pokuspaging  
    {  
        public class ViewModel : INotifyPropertyChanged  
        {  
            private int _pageIndex;  
            public int PageIndex  
            {  
                get  
                {  
                    return _pageIndex;  
                }  
                set  
                {  
                    if (_pageIndex != value)  
                    {  
                        _pageIndex = value;  
                        OnPropertyChanged("PageIndex");  
                    }  
                }  
            }  
     
              
     
            public IEnumerable<int> Data  
            {  
                get  
                {  
                    return Enumerable.Range(1, 1000);  
                }  
            }  
     
            public ViewModel()  
            {  
                PageIndex = 0;  
            }  
     
            protected void OnPropertyChanged(string propertyName)  
            {  
                if (PropertyChanged != null)  
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));  
            }  
              
              
            #region INotifyPropertyChanged Members  
     
            public event PropertyChangedEventHandler PropertyChanged;  
     
            #endregion  
        }  


    Regards

    Tomas Celeda
  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 28 May 2010 Link to this post

    Hi Tomáš Čeleda,

    The exception is thrown because the pager is not fully initialized when the PageIndex binding is evaluated. To solve the problem you can initialize PageIndex in ViewModel.cs with -1; When RadDataPager is loaded it will automatically set PageIndex to 0 and display  the first page. Just create e TwoWay binging for PageIndex so that PageIndex of the View Model and the pager are always synchronized.

    All the best,
    Milan
    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.
  6. abhishek
    abhishek avatar
    2 posts
    Member since:
    Jul 2010

    Posted 19 Jul 2010 Link to this post

    I am passing the pageSize(rows of rows displayed in grid) from the combo box and In the vide model I made the pageindex to -1 before this they have both the page index and page size as nullable of type int where it was working fine but as I need to changes itstead of making the pasesize it should now change depending the selected value by the user.
    here  is the query I am using:

     

     

     

     

     

    query = pageIndex !=

     

    null ?

     

    query.Skip((pageIndex.Value) * pageSize).Take(pageSize) : query.Skip(pageindex.value*pageSize).Take(pageSize);

    I am getting the no of rows selected in the page size.As Could you please suggest me what change do I need to make to enable pagging.Thanks in Advance.

     

  7. abhishek
    abhishek avatar
    2 posts
    Member since:
    Jul 2010

    Posted 19 Jul 2010 Link to this post

    I am passing the pageSize(rows of rows displayed in grid) from the combo box and In the vide model I made the pageindex to -1 before this they have both the page index and page size as nullable of type int where it was working fine but as I need to changes itstead of making the pasesize it should now change depending the selected value by the user.
    here  is the query I am using:

     

     

     

     

     

     

    query = pageIndex !=

     

    null ?

     

    query.Skip((pageIndex.Value) * pageSize).Take(pageSize) : query.Skip(pageindex.value*pageSize).Take(pageSize);

    I am getting the no of rows selected in the page size.As Could you please suggest me what change do I need to make to enable pagging.Thanks in Advance.

     

     

     

  8. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 19 Jul 2010 Link to this post

    Hello abhishek,

    What control are you using? RadDataPager? RadGridView? Can you please send us a small sample project that is runnable and tell us what exactly are you trying to achieve, since we could not understand. We will take a look at the project and think of something.

    Best wishes,
    Ross
    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
  9. Tomáš Čeleda
    Tomáš Čeleda avatar
    15 posts
    Member since:
    Sep 2009

    Posted 20 Jul 2010 Link to this post

    Hello Milan,

    thank you for your response. I tried to set CurrentPage property in model to -1 and then it worked with TwoWay binding as expected.
    A problem has emerged again when Source of the RadDataPager was changed (it is bound to another property, which was set to null). In consequence of setting Source to null, the CurrentPage property is set to -1 by RadDataPager's binding. PropertyChange event is fired in the property setter and then a similar exception is thrown:

    PageIndex must be greater than or equal to 0 when Source is not null and PageSize is greater than 0.
    Parameter name: newPageIndex

    I think that these exceptions are not neccessary and that the control can just ignore invalid PageIndex when its source is null or empty.

    Regards
    Tomas
  10. Answer
    Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 21 Jul 2010 Link to this post

    Hi Tomáš Čeleda,

    By the way, what version are you using? There was a similar issue to the one that you describe (I am not sure whether it is the same or not) but it was fixed. Could you try your project with our 2010 Q2 Release Binaries and see what happens. 

    In case it continues to happen, I have prepared a small dummy project with a pager bound to a ViewModel. Can you try and make my sample project reproduce the exception, since I am not sure how to achieve it. Maybe I am doing something wrong.

    Now onto the topic of exceptions...

    Please, do not take this the wrong way, but these exceptions are necessary because they keep the integrity of the control. We cannot removed them. It is the responsibility of the ViewModel to supply valid values for the properties of the pager. You can weave any kind of logic in your view model to keep the state valid.

    The rule is simple. A pager without a Source is always at PageIndex -1, because there is not Source. Since there is no Source -- there is no paging. Since there is no paging, the only possible page index is -1 because you cannot be on the first page of a Nothing. On the other hand, a pager with a valid Source is always on a page that is greater than -1. I really hope that this makes sense.

    By the way, if you replace RadDataPager with MS DataPager you will see the same behavior.

    If you manage to make my sample project reproduce the exception -- please send it back to me and I will debug it. It is very possible that you have discovered some kind of bug.

    Have in mind that RadDataPager and it's new "friend" RadDataFilter have been moved to our new assembly called Telerik.Windows.Controls.Data. The pager is no longer in the assembly of the grid.

    I am looking forward to hearing from you.

    Best wishes,
    Ross
    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
  11. Tomáš Čeleda
    Tomáš Čeleda avatar
    15 posts
    Member since:
    Sep 2009

    Posted 25 Jul 2010 Link to this post

    Hello Ross,

    thank you for your explanation why exceptions are thrown by RadDataPager. Now I understand it. Your sample solution works as expected. I tried to modify it to reproduce my problem. Unfortunately I wasn't successful. Whatever I tried worked in project based on your solution and did not work in my project.
    The problem is caused when DataSource property (databoud to Source property of pager) is set to null. PageIndex is databound by two way binding, so it is reset to -1 automatically by pager. When PageIndex setter in your project is called, the Pager.Source property is already null. In my project when PageIndex setter is called, the Pager.Source property is still on its original value (not null). Then PropertyChanged event is raised and the exception is thrown.
    I was trying this with versions 2010.2.0609.1040 and 2010.2.0714.1040.

    I had to get my project working this week, so I did an ugly hack (by setting PageIndex manually without any databinding). I will further investigate the problem during following two weeks and let you know if I find something interesting. It is possible that something is broken in the collection Pager is bound to. It is a custom made "lazy" collection that downloads data asynchronously.

    Best regards,
    Tomas Celeda
     
  12. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 25 Jul 2010 Link to this post

    Hello Tomáš Čeleda,

    I am glad that you managed to workaround this. But you must definitely let me know if you can reproduce this in the sample project, because it is quite possible that you have discovered a rare bug or something and I would like to fix it if this is the case.

    Thank you for your feedback and cooperation. I am looking forward to hearing from you.

    Kind regards,
    Ross
    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
  13. Victor
    Victor avatar
    8 posts
    Member since:
    Nov 2010

    Posted 08 Nov 2010 Link to this post

    I've the exactly same problem and the same error. Can you explain me how did you solve the problem?? Thanks in advance.
    PS- The value of CurrentPage is anything but -1.

    My code:

    Source:
    public ObservableCollection<T> Items
    {
        get { return _items; }
        set
        {
            if (Items != value)
            {
                _items = value;
                OnPropertyChanged("Items");
            }
            Navegador.Source = _items;
        }
    }


    CurrentPage (binding):

     

    public int CurrentPage
    {
        get { return _currentPage;}
        set
        {
            _currentPage = value;
            OnPropertyChanged("CurrentPage");
        }
    }

     

     


    CheckPosition
    (On CurrentItem Changed)

     

    public void CheckPosition()
    {
        if (Items != null)
        {
            if (Items.Count != 0)
            {            
                if (CurrentItem != null)
                {
                    int pagina = (Items.IndexOf(CurrentItem)/PagerPageSize);
                    CurrentPage = pagina;
                }
            }
            else
            {
                CurrentPage = 0;
            }
        }
        else
        {
            CurrentPage = -1;
        }
    }

    OnPropertyChanged:

    public new event PropertyChangedEventHandler PropertyChanged;
    protected new void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    XAML
    <Controls:RadDataPager  Grid.Row="1" PageSize="{Binding PagerPageSize, Mode=TwoWay}"
                     Source="{Binding Items, ElementName=radGridView}"
                     DisplayMode="All"
                     AutoEllipsisMode="Both"
                     NumericButtonCount="10"
                     IsTotalItemCountFixed="True"
                     PageIndex="{Binding Path=CurrentPage,Mode=TwoWay}" />

  14. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 08 Nov 2010 Link to this post

    Hello Victor,

    What version are you using? Is it possible to send us the small sample project that you have? To do that you have to open a separate support ticket.

    We will be looking forward to hearing from you.

    Best wishes,
    Ross
    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
  15. Victor
    Victor avatar
    8 posts
    Member since:
    Nov 2010

    Posted 11 Nov 2010 Link to this post

    Apologize me for replying so late.

    I've solved my problem. I tried to create a small sample to send to you, and doing so I found the bug I had.
    I was initializing the PageIndex with 0.

    Thanks anyway for your support, and forgive me for my broken english.
    Regards.
  16. arobadol
    arobadol avatar
    10 posts
    Member since:
    Jun 2006

    Posted 03 Jan 2011 Link to this post

    Dear all,

    I'm having similar problems. I'm using a MVVM as well.
    I manage to solve the first issue by forcing the value -1 instead of the logical value 0 :) in the constructor.
    But:
    1) when the radDataPager set automatically the pageindex to 0 as described above it triggers a search on my ViewModel. Indead I'm listening to the page size event. And by doing so the search is triggered.
    2) I do not want to bind the the pager to my obeservable collection. I bind only PageSize,PAgeIndex and Itemcount
    <telerik:RadDataPager  
                            Grid.Column="0" 
                            Background="Transparent" 
                            BorderThickness="0"
                            PageIndex="{Binding PageIndex,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                            PageSize="{Binding PageSize,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                            ItemCount="{Binding ItemCount,Mode=OneWay}"
                            cm:Message.Attach="[Event PageIndexChanged]=[Action ExecuteSearch]"/>

    by doing so I should have enought information on the pager to handle properly the paging... and then by using the pager, the Page index will be updated-> Execute search...

    Is it possible to use the Pager this way. Or Do I really have to bind the Source Properties.

    I'm using it that way because the My result is embeded in its own ViewModel. This way I can have a ResultCardListViewModel, ResultGridListViewModel and ResultDetailListViewModel. My Source is a property of those viewmodel. My pager is on the View of my SearchViewModel that disply one of the listviewmodel depending on the user selection (Card,List or Details).

    Regards,

    Alexandre
  17. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 04 Jan 2011 Link to this post

    Hello Tomáš Celeda,

    What version are you using?

    The fastest way to resolve your issue would be if you open a separate support ticket and attach your sample project there. We will debug it and see what can be done to achieve your goal. Thanks in advance.

    Greetings,
    Ross
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  18. F
    F avatar
    1 posts
    Member since:
    Apr 2013

    Posted 23 May 2013 Link to this post

    Hello, i have same problem with latest version of telerik. Reproduction:
    RadDataPager with binded PageIndex, mode=TwoWay and without(!) binding ItemSource:

    <telerik:RadDataPager PageSize="{Binding PageSize}"
                                    FontSize="12"
                                    ItemCount="{Binding FindedPointsCount}"
                                    PageIndex="{Binding Page, Mode=TwoWay}"
                                    DisplayMode="FirstLastPreviousNextNumeric, Text"  />

    In ViewModel i tried to set Page to 0 and -1, both gives same error.
    With binding mode OneWay it works fine in design mode but we have to use mode two.
  19. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 27 May 2013 Link to this post

    Hi,

    Can you please send us your dummy sample project for debugging? Open a new support ticket and attach it there. We will immediately take a look at your concrete setup. This will be the fastest way to resolve this issue.

    Thanks in advance.

    Regards,
    Rossen Hristov
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner