Row Count in Paging

20 posts, 2 answers
  1. Maher
    Maher avatar
    19 posts
    Member since:
    Jul 2015

    Posted 28 Dec 2015 Link to this post

    Hi Telerik

    in the gridview paging is it possible to show the row count instead of page Count ?

    if not

    i put a text box and put the row count in it

    in load i put RowCount of the grid

    my problem is after filter

    row count does not change after search i found this

    this.radGridView1.ChildRows.Count;

    but this show only the page size if the row count after filter=60

    and page size=20 this statement return 20 

    how to get the full row count after filter

     

    thank you

  2. Hristo
    Admin
    Hristo avatar
    1517 posts

    Posted 29 Dec 2015 Link to this post

    Hi Maher,

    Thank you for writing.

    Yes, it is possible to achieve the desired behavior. Please note, however, this type of functionality is not provided out of the box. In order to accomplish your task you would need to sync the labels with the current PageSize and total rows count values. If I have understood correctly you would also like the text box to display the page size. 

    In order the text box to be functional so that the RadGridView.PageSize changes whenever there is a new input, we are also going to need to unsubscribe it from the KeyDown event and implement our own delegate. Please see my code snippet below:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
     
            new RadControlSpyForm().Show();
     
            this.radGridView1.DataSource = this.GetData(1000);
            this.radGridView1.EnableFiltering = true;
            this.radGridView1.EnablePaging = true;
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
     
            this.radGridView1.Rows.CollectionChanged += Rows_CollectionChanged;
            this.radGridView1.PageChanged += radGridView1_PageChanged;
        }
     
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            CommandBarTextBox pageNumberTextBox = this.radGridView1.GridViewElement.PagingPanelElement.PageNumberTextBox;
            EventInfo ei = pageNumberTextBox.GetType().GetEvent("KeyDown", BindingFlags.Public | BindingFlags.Instance);
            if (ei != null)
            {
                Type delType = ei.EventHandlerType;
                MethodInfo mi = this.radGridView1.GridViewElement.PagingPanelElement.GetType().GetMethod("PageNumberTextBox_KeyDown", BindingFlags.NonPublic | BindingFlags.Instance);
                if (mi != null)
                {
                    Delegate del = Delegate.CreateDelegate(delType, this.radGridView1.GridViewElement.PagingPanelElement, mi);
                    ei.RemoveEventHandler(pageNumberTextBox, del);
     
                    this.radGridView1.GridViewElement.PagingPanelElement.PageNumberTextBox.KeyDown += PageNumberTextBox_KeyDown;
                }
            }
        }
     
        protected override void OnShown(EventArgs e)
        {
            this.ChangePageLabels();
        }
     
        private void PageNumberTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter)
            {
                return;
            }
     
            int pageSize = -1;
            if (int.TryParse(((RadTextBoxItem)sender).Text, out pageSize))
            {
                this.radGridView1.PageSize = pageSize;
                this.ChangePageLabels();
            }
        }
     
        private void Rows_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
        {
            this.ChangePageLabels();
        }
     
        private void radGridView1_PageChanged(object sender, EventArgs e)
        {
            this.ChangePageLabels();
        }
     
        private void ChangePageLabels()
        {
            this.radGridView1.GridViewElement.PagingPanelElement.PageLabel.Text = "Page Size";
            this.radGridView1.GridViewElement.PagingPanelElement.NumberOfPagesLabel.Text = this.radGridView1.Rows.Count + "";
            this.radGridView1.GridViewElement.PagingPanelElement.PageNumberTextBox.TextBoxElement.TextBoxItem.Text = this.radGridView1.PageSize + "";
        }
         
        private DataTable GetData(int count)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Age", typeof(int));
            dt.Columns.Add("Date", typeof(DateTime));
            dt.Columns.Add("Bool", typeof(bool));
     
            for (int i = 0; i < count; i++)
            {
     
                dt.Rows.Add("Name " + i, i, DateTime.Now.AddMinutes(i), i % 2 == 0 ? true : false);
            }
     
            return dt;
        }
    }
     
    Regarding your other question about the ChildRows, this property returns the rows in the current template. When paging is enabled it will be the value of the PageSize property. If you apply a filter it will take into consideration the filtered rows as well. More information is available here: Rows vs ChildRows.

    I am also sending you a short video showing the result on my end.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. Maher
    Maher avatar
    19 posts
    Member since:
    Jul 2015

    Posted 29 Dec 2015 in reply to Hristo Link to this post

    Thank you for you answer

    but you did not answer my question

    how to get Total Rows after filter when it is larger than page size

    (ChildRows get page size , RowCount get all rows)

     

     

  4. Answer
    Hristo
    Admin
    Hristo avatar
    1517 posts

    Posted 30 Dec 2015 Link to this post

    Hi Maher,

    Thank you for writing back.

    You can get the count of the filtered rows by accessing the ItemCount property of DataView of the grid:
    int filteredPages = this.radGridView1.MasterTemplate.DataView.ItemCount;

    I hope this helps. Please let me know if you need further assistance.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  5. Maher
    Maher avatar
    19 posts
    Member since:
    Jul 2015

    Posted 30 Dec 2015 in reply to Hristo Link to this post

    Thank you

    This is definitely the right answer

    there is another Issue

    can i make error indication on the summery row

    here is the situation

    Account     

     

  6. Maher
    Maher avatar
    19 posts
    Member since:
    Jul 2015

    Posted 30 Dec 2015 in reply to Maher Link to this post

    can i make error indication on the summery row
    here is the situation

     

    Account               Profit              Expenss

    Sales                   20000               15000

    Salaries                 0                       15000

    Services               20000                 10000

    Total                      40000                    40000

     

    i want to validate that Total of income = to total of expenses by maybe change the background or some thing  in the summery row

    Thank you Again

  7. Hristo
    Admin
    Hristo avatar
    1517 posts

    Posted 31 Dec 2015 Link to this post

    Hi Maher,

    Thank you for writing.

    You can use the ViewRowFormatting or ViewCellFormatting events and define different styling for the whole row or for particular cells: Formatting Rows, Formatting Cells. The summary row can also be customized. More information is available here: Summary Rows.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  8. Maher
    Maher avatar
    19 posts
    Member since:
    Jul 2015

    Posted 31 Dec 2015 in reply to Hristo Link to this post

    Thank you

    but it did not work with me

     

    this is the code for the summary row

    Dim summaryI_D As New GridViewSummaryItem()
            summaryI_D.Name = "F_DEBIT"
            summaryI_D.FormatString = "{0:F2}"
            summaryI_D.Aggregate = GridAggregateFunction.Sum
            Dim summaryRowI As New GridViewSummaryRowItem()
            summaryRowI.Add(summaryI_D)
     
            Dim summaryI_C As New GridViewSummaryItem()
            summaryI_C.Name = "F_CREDIT"
            summaryI_C.FormatString = "{0:F2}"
            summaryI_C.Aggregate = GridAggregateFunction.Sum
            summaryRowI.Add(summaryI_C)

    this for formatting

    Private Sub RadGridTrans_CellFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridTrans.CellFormatting
          
          If TypeOf e.CellElement Is GridSummaryCellElement Then

        ' Code Never get inside the if statment

              e.CellElement.DrawBorder = True
              e.CellElement.BorderBoxStyle = BorderBoxStyle.FourBorders
              e.CellElement.BorderLeftWidth = 0
              e.CellElement.BorderRightWidth = 0
              e.CellElement.BorderBottomWidth = 0
              e.CellElement.BorderTopWidth = 1
              e.CellElement.BorderTopColor = Color.Black
              e.CellElement.ForeColor = Color.Red
              e.CellElement.TextAlignment = ContentAlignment.MiddleLeft
          End If
      End Sub

    the code never get inside the if statment

    TypeOf e.CellElement is always datacell or commandcell never  GridSummaryCellElement

    what am I missing ?
  9. Answer
    Hristo
    Admin
    Hristo avatar
    1517 posts

    Posted 04 Jan 2016 Link to this post

    Hi Maher,

    Thank you for writing back.

    The CellFormatting event is fired only for the data cells. As I wrote in my previous post, in order to customize the appearance of the summary cells you would need to handle the ViewCellFormatting event.

    I hope this information is useful. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  10. Maher
    Maher avatar
    19 posts
    Member since:
    Jul 2015

    Posted 07 Jan 2016 Link to this post

    Sorry My Mistake

    that worked fine

    Thank you

  11. Aseman
    Aseman avatar
    38 posts
    Member since:
    Aug 2019

    Posted 15 Dec 2019 in reply to Hristo Link to this post

    hi hristo

    in my rad grid view in win form,in every page which I customed , I have reseted Number

    it means my row number in per page get reset,but I`d like to be increased.

    what should I do?

  12. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3707 posts

    Posted 16 Dec 2019 Link to this post

    Hello, Aseman,    

    The following KB article demonstrates a sample approach how to get all rows in RadGridView with paging. Thus, you can use the IndexOf method to get the index of the respective row to get the correct row number : https://docs.telerik.com/devtools/winforms/knowledge-base/get-all-filtered-rows-in-gridview-with-paging

            public RadForm1()
            {
                InitializeComponent();
    
                this.radGridView1.EnablePaging = true;
                this.radGridView1.ViewCellFormatting += radGridView1_ViewCellFormatting;
                dataView = this.radGridView1.MasterTemplate.DataView as GridDataView;
            }
    
            GridDataView dataView;
    
            private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
            {
                if (e.CellElement is GridRowHeaderCellElement && e.Row is GridViewDataRowInfo)
                {
                    e.CellElement.Text = dataView.Indexer.Items.IndexOf(e.Row).ToString();
                }
            }

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  13. Aseman
    Aseman avatar
    38 posts
    Member since:
    Aug 2019

    Posted 16 Dec 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Dear Dess

    Thank you for always stepping in to help when We need you most.

    I Mean of per page has numbers from 1 to 20 , not Continuously 1 to 1000

    page 1 : number 1 to 20

    page 2 : number 1 to 20

    page 3 : number 1 to 20

    .... and So On

  14. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3707 posts

    Posted 16 Dec 2019 Link to this post

    Hello, Aseman,    

    I have attached my sample project for your reference which utilizes the suggested code from my previous reply. You can see that the row numbers are increasing on each page, not 1-20 numbers for every page. Am I missing something?

    Could you please specify the exact steps how to reproduce the problem?

    I am looking forward to your reply.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  15. Aseman
    Aseman avatar
    38 posts
    Member since:
    Aug 2019

    Posted 16 Dec 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hello

    I wrote Custom Pagination (Server Side Paging) on Win Form By use of Linq to Sql`(Because Of 2 Million Records ) relatively successful. so I`m loading  20 (Page Size) Records for every page in my Data source

    .it means I don`t use a data source with 2 million records .

    then I have:

    Page 1 : 1 to 20

    Page 2 : 1 to 20

    Page 3 : 1 to 20

    ... and so on.

     

     

     

  16. Aseman
    Aseman avatar
    38 posts
    Member since:
    Aug 2019

    Posted 16 Dec 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hello

    I Wrote Custom Pagination On Win Form By LINQ to SQL. and Loading 20 Records In Data source For every Page , because of Lots Of Records and Slowly Operations.(More Data On : "https://www.telerik.com/blogs/emulating-paging-with-radgridview-for-winforms-and-linq-with-1-million-records")

    then I got this result:

    Page 1 : 1 to 20

    Page 1 : 1 to 20

    Page 1 : 1 to 20

     

     

  17. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3707 posts

    Posted 17 Dec 2019 Link to this post

    Hello, Aseman,     

    I would like to note that the referred blog post was released back in 2008 before the major refactoring of RadGridView in 2010 and even before introducing its paging functionality. The approach in the tutorial actually extracts the data necessary for the imaginary page and sets the DataSource of RadGridView. This is a simulation of paging functionality and you have as DataSource only the current page. 

    Following this approach, the possible solution that I can suggest for calculating the correct row number is to consider the current page number and the page size as well. The calculation would be like this: row number = page number * page size + row index. Thus, if you have 20 rows per page and you are currently on the 3rd page, the 5th row will have the following row number = 3*20+5=65.

    Could you please give this approach a try and see how it works?

    An alternative solution that I would suggest is using RadVirtualGrid. It is a grid component developed on top of Telerik Presentation Framework which provides a convenient way to implement your own data management operations and optimizes the performance when interacting with large amounts of data. Additional information is available in the online documentation: https://docs.telerik.com/devtools/winforms/controls/virtualgrid/overview.html 

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

     

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  18. Aseman
    Aseman avatar
    38 posts
    Member since:
    Aug 2019

    Posted 17 Dec 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thank you for being patient and helping me improve.

    You Solved My Problem.

     

  19. Aseman
    Aseman avatar
    38 posts
    Member since:
    Aug 2019

    Posted 23 Dec 2019 Link to this post

    Hello Dess

    I Have Some Problem with Loading My RadGridView.

    I've got 100 Records in my table in DB.

    My Page Size is 25 But My Grid Loading  20 Records  in the first Page and  the other pages Just  Show 5 Records Of 25 Records .

    thank You 

     

  20. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3707 posts

    Posted 23 Dec 2019 Link to this post

    Hello, Aseman,     

    Following the provided information, I have modified my sample project which is bound to a DataTable with 100 records. The PageSize is set to 25 on my end. 
    I was unable to reproduce the issue you are facing. Please refer to the attached gif file illustrating the behavior on my end with the specified version. I have attached my sample project. Am I missing something?  Could you please specify the exact steps how to reproduce the problem? Thank you in advance.

    I am looking forward to your reply.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top