Semantics of Rows.Count changed in 2010Q3 ?

17 posts, 3 answers
  1. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 11 Nov 2010 Link to this post


    In Versions prior to Q3 2010,  when I filtered the grid,

    myGrid.Rows.Count    

    counted only the visible rows, now it returns the total rows.
    How can I get the number of currently visible Rows in the FilterChanged event handler?

    Regards
    Erwin
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 11 Nov 2010 Link to this post

    Hi Erwin,

    I'm still getting my Q3 install uptogether, but this may help (from the release notes)

    BREAKING CHANGE: The Rows collection of GridViewTemplate now contains all bound/unbound rows. The filtered, grouped, and sorted lists of rows can be accessed from the ChildRows collection of GridViewTemplate or from every GridViewRowInfo in a hierarchical view of rows.


    hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 11 Nov 2010 Link to this post

    Thanks, Richard!

    My fault, was too lazy to read the Breaking Changes Section...

    Wanted to play around with the new Excel filtering options but find the UI rather confusing, with 2 filter buttons with inconsistent dialogs behind - what do you think?

    Erwin

  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 11 Nov 2010 Link to this post

    Hi Erwin,

    Glad I could help. I'm still trying to sort out a couple of issues since upgrading at the moment, but I'll have a look at it and try and let you know my thoughts. I saw it in the release details, but haven't had chance to have a play yet.
    In the meantime, would you mind marking as answer.

    Thanks. Speak soon.
    Richard

  6. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 11 Nov 2010 Link to this post

    Hello Erwin,

    Just like Richard said, we have a breaking change in the Rows collection and it contains all rows of a GridViewTemplate without sorting, filtering, grouping. The ChildRows contains the hierarchical view of the rows after the data operations have been applied. For example, if we have grouping on two levels, the ChildRows contains GridViewGroupRows and the ChildRows collection of each group row contains group rows. In hierarchy mode you can navigate from MasterTemplate to all inner levels using ChildRows. If you want to get a flat collection of the visible data rows for a GridViewTemplate, you must use the DataView property. The DataView of a GridViewTemplate contains the sorted and filtered rows of this template.

    I hope that this clarifies the new API.

    Regards,
    Julian Benkov
    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
  7. Xavier Soares
    Xavier Soares avatar
    39 posts
    Member since:
    Jun 2008

    Posted 07 Feb 2011 Link to this post

    Hello,

    Sorry my ignorance, but How can I get the number of currently visible Rows in the FilterChanged event handler?

    Can't see where's The Rows collection of GridViewTemplate

    Best Regards
    Luis Mauricio
  8. Xavier Soares
    Xavier Soares avatar
    39 posts
    Member since:
    Jun 2008

    Posted 07 Feb 2011 Link to this post

    Nevermind! Got it
  9. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 10 Feb 2011 Link to this post

    Hello Luis Mauricio,

    You can use the ChildRows property that can be accessed from RadGridView. If you have any additional questions, do not hesitate to ask.

     All the best,
    Julian Benkov
    the Telerik team
    Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
  10. Answer
    erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 10 Feb 2011 Link to this post

    Also note, that when your Grid is grouped you have to recursively get the ChildRows Count.
    I use the following code in my derived Grid control.
    public long GetVisibleRows()
    {
        return _getVisibleRows(this.MasterTemplate.ChildRows);
    }
     
    private long _getVisibleRows(GridViewChildRowCollection rows)
    {
        long i=0;
        foreach (GridViewRowInfo row in rows)
        {
            if (row is GridViewGroupRowInfo)
            {
                i += _getVisibleRows(row.ChildRows);
                continue;
            }
     
            i += 1;
        }
        return i;
    }
  11. Eric
    Eric avatar
    24 posts
    Member since:
    Jul 2011

    Posted 19 Oct 2011 Link to this post

    Thanks Erwin.  One point and tweek to your solution... your version also counts the group rows.  In my case, I needed only the leave nodes (excluding the groups) so I have an extra else clause so that you only count the row if it's not a group:

    Private Function GetVisibleRows(rows As GridViewChildRowCollection) As Integer
     
        Dim iCount As Integer = 0
        For Each row As GridViewRowInfo In rows
     
            If TypeOf row Is GridViewGroupRowInfo Then
                iCount += GetVisibleRows(row.ChildRows)
            Else
                iCount += 1
            End If
     
        Next
     
        Return iCount
     
    End Function



  12. Answer
    erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 20 Oct 2011 Link to this post

    Hi Eric,

    I  think your code and mine are equivalent. Maybe it's a c# to VB misunderstanding.
    I do not count the group row itself. Notice the continue statement which causes an immediate new iteration of the for each loop.
    In my code i += 1 is not executed for group rows.

    If I'm right VB.net does also have a Continue For statement since VB.Net 2005. I guess it's a matter of personal coding preference.
    Coming from a c++ background, continue seems natural to me ...
    Private Function GetVisibleRows(rows As GridViewChildRowCollection) As Integer
      
        Dim iCount As Integer = 0
      
        For Each row As GridViewRowInfo In rows
       
            If TypeOf row Is GridViewGroupRowInfo Then
      
                iCount += GetVisibleRows(row.ChildRows)
                Continue For
      
            End If
      
            iCount += 1
      
        Next
      
        Return iCount
     
    End Function


    just noticed the telerik parser here does not seem to recognize Continue ...

    Regards
    Erwin

  13. Eric
    Eric avatar
    24 posts
    Member since:
    Jul 2011

    Posted 20 Oct 2011 Link to this post

    Ah, now I see.  My bad, I must have skipped that when I transposed into VB :).  Also, I did make another revision (to my code) as I have a case where we are using heirarchy rows so my new code is now:

    Private Function GetVisibleRows(rows As GridViewChildRowCollection) As Integer
     
        Dim iCount As Integer = 0
        For Each row As GridViewRowInfo In rows
     
            If TypeOf row Is GridViewGroupRowInfo OrElse TypeOf row Is GridViewHierarchyRowInfo Then
                iCount += GetVisibleRows(row.ChildRows)
            Else
                iCount += 1
            End If
     
        Next
     
        Return iCount
     
    End Function


    thanks again,
    Eric
  14. Mark
    Mark avatar
    8 posts
    Member since:
    Jun 2011

    Posted 18 Dec 2011 Link to this post

    I swear its always a pain trying to do what you would think is the easiest thing...anyways here is my solution that is much more elegant than any of ones i saw:

    int rowCount = myGridView.ChildRows.Count(row => row.IsVisible);

    works with both filters applied and if you manually hide rows by setting row.IsVisible
  15. Jeen
    Jeen avatar
    13 posts
    Member since:
    Jul 2014

    Posted 17 Jul 2014 Link to this post

    Hi, everyone.
    I found this thread in Google search and it seemed the closest to the issue I've got. Sorry if I had to create a new topic for this.

    I have encountered a problem while working with radgridview for winforms. I was to implement multi-level grouping (namely: 3 levels) in the grid, then apply filters to it, and after that count the total number of visible filtered rows in all the groups/subgroups.
    Graphically the grouping looks like this:
            Client  -
                           Product   -
                                                Price 
      
    I used "ChildRows" collection, but it always gives me "1", no matter how many filters or groups I apply.
    However, when I disable grouping, it seems to work just fine with filters. Therefore, the multi-level grouping seems to be the obstacle. Since there is one row in the very first subgroup of the major group, I guess the "ChildRows.Count" shows this one and doesn't bother seeing the rest of the rows in the other subgroups grid.
    I need your advice.
    Thank you very much in advance.

    Best regards,
    JeenB
  16. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 21 Jul 2014 in reply to Jeen Link to this post

    Hi Jeen, 

    I suppose you post your code here, otherwise you probably won't get a satisfying answer. Recursively counting the child rows should work.
    When you are always getting exactly 1 row, chances are you are counting the grouping row itself.

    Regards
    Erwin
  17. George
    Admin
    George avatar
    500 posts

    Posted 22 Jul 2014 Link to this post

    Hello Jeen,

    Thank you for writing.

    I am not sure how you are iterating your rows, however it seems that a simple recursive method which iterates the ChildRows of each row does the job:
    private void IterateRows(GridViewChildRowCollection childRows)
    {
        foreach (GridViewRowInfo row in childRows)
        {
            this.IterateRows(row.ChildRows);
        }
    }

    Below you can find a sample project which counts the rows in RadGridView recursively and shows it in a RadMessageBox.

    Let me know, should you have further questions.

    Regards,
    George
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  18. Jeen
    Jeen avatar
    13 posts
    Member since:
    Jul 2014

    Posted 04 Aug 2014 Link to this post

    Hi, Erwin and George.
    Excuse me for the delay with the answer.

    Thank you, Erwin, for the hint.
    Thank you, George, for a solution. It seems to work fine)
     
    Best regards,
    Jeen
Back to Top
UI for WinForms is Visual Studio 2017 Ready