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

Problem with RadGridView

8 Answers 235 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ehsan
Top achievements
Rank 1
Ehsan asked on 14 Jun 2010, 08:09 AM

Im using RadGridView with a RadDataPager . I use EndlessPagedCollectionView from telerik samples .
This is part of my xaml :

 

<

 

 

telerikg:RadGridView Grid.Row="1" AutoGeneratingColumn="radGridView_AutoGeneratingColumn" Name="radGridView" ItemsSource="{Binding PagedSource, ElementName=radDataPager}" Width="700">

 

 

 

 

 

 

 

 

</telerikg:RadGridView>

 

 

 

 

<telerikg:RadDataPager Grid.Row="2" x:Name="radDataPager" PageSize="10" NumericButtonCount="5"  DisplayMode="First, Previous, Next, Text"/>

 

 

 

 

 

& this is part of my behind code :

 

radDataPager.DisplayMode = Telerik.Windows.Controls.

 

PagerDisplayModes.All;

 

radDataPager.AutoEllipsisMode = Telerik.Windows.Controls.

 

AutoEllipsisModes.Both;

 

radDataPager.Source =

 

new EndlessPagedCollectionView();

 

 

when I run the program, there are two problems :

1- GetEnumerator() method which is heart of EndlessPagedCollectionView class, executes several times (between 3 to 6 with no discipline) .
This happens even if i dont use RadDataPager & bind RadGridView directly to the EndlessPagedCollectionView .
Now if I want to retrive data from a database, it couse an awful overhead !

2 - When I use xml data or client side generated data to create an Enumeration in GetEnumerator() method, my data displays OK, but when i load data from server in an async manner, i see a white page for first time I click on a page number in radDataPager, but when i click another number & then return again, that page displays ok !

can anybody help me please ?

8 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 15 Jun 2010, 07:41 AM
Hello Ehsan,

Could you please open a separate support ticket and attach a sample project that reproduces the behavior. Thanks in advance.

Sincerely yours,
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
Vladimir No
Top achievements
Rank 1
answered on 13 Aug 2010, 09:44 AM
Sorry, but where can I get sample project with "EndlessPagedCollectionView" class implementation?

Thanks.
0
Rossen Hristov
Telerik team
answered on 13 Aug 2010, 09:50 AM
Hello Vladimir No,

There isn't such a project.

I can send you the source code though. Please, find it attached.

Have in mind that this is just an example and not an official feature and it provided on an "as is" basis. We will not support this reference implementation, so use it on your own discretion:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Telerik.Windows.Data;
using System.ComponentModel;
using System.Collections.Specialized;
using System.Windows.Data;
using System.Globalization;
 
namespace Telerik.Windows.Examples.GridView
{
    /// <summary>
    /// Endless paged collection view for testing purposes.
    /// </summary>
    public class EndlessPagedCollectionView : IEnumerable
        , IPagedCollectionView
        , INotifyPropertyChanged
        , INotifyCollectionChanged
    {
        public event EventHandler<EventArgs> PageChanged;
        public event EventHandler<PageChangingEventArgs> PageChanging;
        public event PropertyChangedEventHandler PropertyChanged;
        public event NotifyCollectionChangedEventHandler CollectionChanged;
 
        private int pageIndex = -1;
        private bool isPageChanging;
        private int pageSize;
 
        /// <summary>
        /// We always can. We are endless.
        /// </summary>
        bool IPagedCollectionView.CanChangePage
        {
            get { return true; }
        }
 
        bool IPagedCollectionView.IsPageChanging
        {
            get { return this.isPageChanging; }
        }
 
        /// <summary>
        /// Visual Basic is so lame!
        /// </summary>
        private void SetIsPageChanging(bool value)
        {
            if (this.isPageChanging != value)
            {
                this.isPageChanging = value;
                this.OnPropertyChanged("IsPageChanging");
            }
        }
 
        /// <summary>
        /// Since we are endless, the item count is
        /// the amount of items currently known to exist.
        /// In other words the item count is whatever we
        /// have reached.
        /// </summary>
        int IPagedCollectionView.ItemCount
        {
            get
            {
                return (((IPagedCollectionView)this).PageIndex + 1) * ((IPagedCollectionView)this).PageSize;
            }
        }
 
        bool IPagedCollectionView.MoveToFirstPage()
        {
            return ((IPagedCollectionView)this).MoveToPage(0);
        }
 
        bool IPagedCollectionView.MoveToLastPage()
        {
            //We cannot move to the last page since we are endless :)
            return false;
        }
 
        bool IPagedCollectionView.MoveToNextPage()
        {
            return ((IPagedCollectionView)this).MoveToPage(((IPagedCollectionView)this).PageIndex + 1);
        }
 
        bool IPagedCollectionView.MoveToPage(int pageIndex)
        {
            if (this.OnPageChanging(pageIndex) && pageIndex != -1)
            {
                return false;
            }
 
            this.SetIsPageChanging(true);
            this.pageIndex = pageIndex;
            this.SetIsPageChanging(false);
 
            this.OnPropertyChanged("PageIndex");
            this.OnPropertyChanged("ItemCount");
            this.OnPageChanged();
 
            // Call this to inform all listeners that data has changed.
            this.OnCollectionChanged();
 
            return true;
        }
 
        bool IPagedCollectionView.MoveToPreviousPage()
        {
            return ((IPagedCollectionView)this).MoveToPage(((IPagedCollectionView)this).PageIndex - 1);
        }
 
        int IPagedCollectionView.PageIndex
        {
            get { return this.pageIndex; }
        }
 
        int IPagedCollectionView.PageSize
        {
            get
            {
                return this.pageSize;
            }
            set
            {
                if (value < 1)
                {
                    throw new ArgumentOutOfRangeException("value", "The PageSize of an endless collection should be positive.");
                }
 
                if (this.pageSize != value)
                {
                    this.pageSize = value;
                    this.OnPropertyChanged("PageSize");
                    this.OnPropertyChanged("ItemCount");
 
                    // Behave like good collections do.
                    ((IPagedCollectionView)this).MoveToFirstPage();
                }
            }
        }
 
        /// <summary>
        /// We don't know this. Remember we are endless.
        /// </summary>
        int IPagedCollectionView.TotalItemCount
        {
            get { return -1; }
        }
 
        public System.Collections.IEnumerator GetEnumerator()
        {
            // The best part -- true endlessness ;)
            // Now this might crash if we overflow Int32, but in a
            // real scenario new "items" will be returned forever.
            IEnumerable<Order> items = from id in Enumerable.Range(((IPagedCollectionView)this).PageIndex * ((IPagedCollectionView)this).PageSize, ((IPagedCollectionView)this).PageSize)
                                       select new Order(id);
            return items.GetEnumerator();
        }
 
        private void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventArgs e = new PropertyChangedEventArgs(propertyName);
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, e);
            }
        }
 
        private bool OnPageChanging(int newPageIndex)
        {
            PageChangingEventArgs e = new PageChangingEventArgs(newPageIndex);
            if (this.PageChanging != null)
            {
                this.PageChanging(this, e);
            }
 
            return e.Cancel;
        }
 
        private void OnPageChanged()
        {
            EventArgs e = EventArgs.Empty;
            if (this.PageChanged != null)
            {
                this.PageChanged(this, e);
            }
        }
 
        private void OnCollectionChanged()
        {
            NotifyCollectionChangedEventArgs e = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
            if (this.CollectionChanged != null)
            {
                this.CollectionChanged(this, e);
            }
        }
 
        /// <summary>
        /// Sample Order
        /// </summary>
        public class Order
        {
            private int id;
            private DateTime date;
            private double amount;
            private bool confirmed;
            private string code;
            private string country;
 
            /// <summary>
            /// Gets the ID.
            /// </summary>
            /// <value>The ID.</value>
            public int ID
            {
                get { return this.id; }
            }
 
            /// <summary>
            /// Gets or sets the date.
            /// </summary>
            /// <value>The date.</value>
            public DateTime Date
            {
                get
                {
                    return this.date;
                }
                private set
                {
                    this.date = value;
                }
            }
 
            /// <summary>
            /// Gets or sets the amount.
            /// </summary>
            /// <value>The amount.</value>
            public double Amount
            {
                get
                {
                    return this.amount;
                }
                private set
                {
                    this.amount = value;
                }
            }
 
            /// <summary>
            /// Gets or sets a value indicating whether this <see cref="Order"/> is confirmed.
            /// </summary>
            /// <value><c>true</c> if confirmed; otherwise, <c>false</c>.</value>
            public bool Confirmed
            {
                get
                {
                    return this.confirmed;
                }
                private set
                {
                    this.confirmed = value;
                }
            }
 
            /// <summary>
            /// Gets or sets the code.
            /// </summary>
            /// <value>The code.</value>
            public string Code
            {
                get
                {
                    return this.code;
                }
                private set
                {
                    this.code = value;
                }
            }
 
            /// <summary>
            /// Gets or sets the country.
            /// </summary>
            /// <value>The country.</value>
            public string Country
            {
                get
                {
                    return this.country;
                }
                private set
                {
                    this.country = value;
                }
            }
 
            /// <summary>
            /// Initializes a new instance of the <see cref="Order"/> class.
            /// </summary>
            /// <param name="id">The id.</param>
            public Order(int id)
            {
                this.id = id;
                int random = new Random(id).Next(-100, 100);
                this.Date = DateTime.Now.AddDays(random);
                this.Amount = Math.Abs(random);
                this.Confirmed = random % 2 == 0;
 
                int someRandom = Math.Abs(this.id.GetHashCode()) / 10
                    + Math.Abs(this.Date.GetHashCode()) / 10
                    + Math.Abs(this.Amount.GetHashCode()) / 10
                    + Math.Abs(this.Confirmed.GetHashCode()) / 10;
                this.Code = someRandom.ToString() + someRandom.ToString();
 
                switch (random % 5)
                {
                    case 0:
                        this.Country = "USA";
                        break;
                    case 1:
                        this.Country = "UK";
                        break;
                    case 2:
                        this.Country = "Germany";
                        break;
                    case 3:
                        this.Country = "Spain";
                        break;
                    case 4:
                        this.Country = "France";
                        break;
                    default:
                        this.Country = "Other";
                        break;
                }
            }
        }
    }
}


By the way, you might be interested in RadDataPager's new feature called "Unbound Mode". You can specify the total number of items and simply use the pager for its user interface. By attaching to its PageIndexChanged event you can page anything.

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
Vladimir No
Top achievements
Rank 1
answered on 13 Aug 2010, 10:17 AM
Thnks a lot.

>By the way, you might be interested in RadDataPager's new feature called "Unbound Mode".

Yes, I am. Definitely, this is exactly what I need. But, as I can see, this feature still not implemented. So for now "EndlessPagedCollectionView" is the only option.
0
Rossen Hristov
Telerik team
answered on 13 Aug 2010, 11:26 AM
Hi Vladimir No,

If you download our Service Pack 1 version released yesterday you will find it.

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
Andrew
Top achievements
Rank 1
answered on 16 Oct 2010, 01:22 AM
I am looking for a recommended approach to using raddatapager, radgridview with devforce to page through large files downloading one page at a time. 

I see no reason to download the whole file, and some of the files are just too big to do that even if you wanted to.

So somehow we need to tell the raddatapager the size of the entire file then let it do its stuff.

I assume a query designed to skip (pages* pagesize) and take (pagesize) would be required also.

Binding to EntityQueryPagedCollectionView seems to get about half way there.  It works until you want to filter.  Can you please demonstrate server side filtering using devforce instead of RIA.  Since Devforce can actually support all your filtering, it would seem to make more sense anyway.
0
Pavel Pavlov
Telerik team
answered on 20 Oct 2010, 01:37 PM
Hi Andrew,

As stated before , the unbound mode of RadDataPager may be used in scenarios where you need to tell the pager the size of the whole collection. Then the logic of extracting the pages  from the server may be implemented manually and placed in the PageIndexChanged event handler of radDataPager.

Best wishes,
Pavel Pavlov
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
Anuj
Top achievements
Rank 1
answered on 16 Nov 2011, 10:09 AM
Hello Everyone,
We hide extra columns but here appear extra blank columns for the same like Invoice Number,Vendor Name,Vendor Type,Product Name,Analysis columns shows according to conditions on telrik grid and those columns hide respect to condition by code behind and not reflect on running mode in asp .net (C#) .

if do you have solution for the removing those extra blank columns kindly suggest  me.

Please have look Jpg file.



Tags
GridView
Asked by
Ehsan
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Vladimir No
Top achievements
Rank 1
Andrew
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Anuj
Top achievements
Rank 1
Share this question
or