Row Count in Paging

10 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
    716 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. UI for WinForms is Visual Studio 2017 Ready
  4. 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)

     

     

  5. Answer
    Hristo
    Admin
    Hristo avatar
    716 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
  6. 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     

     

  7. 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

  8. Hristo
    Admin
    Hristo avatar
    716 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
  9. 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 ?
  10. Answer
    Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 04 Jan 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
  11. Maher
    Maher avatar
    19 posts
    Member since:
    Jul 2015

    Posted 07 Jan Link to this post

    Sorry My Mistake

    that worked fine

    Thank you

Back to Top
UI for WinForms is Visual Studio 2017 Ready