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

Binding to RadDataPager.PageIndex property

17 Answers 597 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tomáš Čeleda
Top achievements
Rank 2
Tomáš Čeleda asked on 11 May 2010, 09:31 PM
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?

17 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 12 May 2010, 07:44 AM
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.
0
Tomáš Čeleda
Top achievements
Rank 2
answered on 26 May 2010, 07:15 AM
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
0
Milan
Telerik team
answered on 28 May 2010, 04:25 PM
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.
0
abhishek
Top achievements
Rank 1
answered on 19 Jul 2010, 05:26 AM

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.

 

0
abhishek
Top achievements
Rank 1
answered on 19 Jul 2010, 05:28 AM

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.

 

 

 

0
Rossen Hristov
Telerik team
answered on 19 Jul 2010, 10:40 AM
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
0
Tomáš Čeleda
Top achievements
Rank 2
answered on 20 Jul 2010, 10:23 PM
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
0
Accepted
Rossen Hristov
Telerik team
answered on 21 Jul 2010, 10:22 AM
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
0
Tomáš Čeleda
Top achievements
Rank 2
answered on 25 Jul 2010, 01:29 PM
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
 
0
Rossen Hristov
Telerik team
answered on 25 Jul 2010, 04:10 PM
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
0
Victor
Top achievements
Rank 1
answered on 08 Nov 2010, 02:34 PM
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}" />

0
Rossen Hristov
Telerik team
answered on 08 Nov 2010, 03:41 PM
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
0
Victor
Top achievements
Rank 1
answered on 11 Nov 2010, 02:16 PM
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.
0
Alexandre
Top achievements
Rank 2
answered on 04 Jan 2011, 03:11 AM
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
0
Rossen Hristov
Telerik team
answered on 04 Jan 2011, 12:25 PM
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
0
F
Top achievements
Rank 1
answered on 23 May 2013, 12:12 PM
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.
0
Rossen Hristov
Telerik team
answered on 27 May 2013, 07:40 AM
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.

Tags
GridView
Asked by
Tomáš Čeleda
Top achievements
Rank 2
Answers by
Milan
Telerik team
Tomáš Čeleda
Top achievements
Rank 2
abhishek
Top achievements
Rank 1
Rossen Hristov
Telerik team
Victor
Top achievements
Rank 1
Alexandre
Top achievements
Rank 2
F
Top achievements
Rank 1
Share this question
or