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

Semantics of Rows.Count changed in 2010Q3 ?

16 Answers 168 Views
GridView
This is a migrated thread and some comments may be shown as answers.
erwin
Top achievements
Rank 1
Veteran
erwin asked on 11 Nov 2010, 04:53 PM

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

16 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 11 Nov 2010, 05:05 PM
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
0
erwin
Top achievements
Rank 1
Veteran
answered on 11 Nov 2010, 05:37 PM
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

0
Richard Slade
Top achievements
Rank 2
answered on 11 Nov 2010, 05:43 PM
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

0
Julian Benkov
Telerik team
answered on 11 Nov 2010, 05:51 PM
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
0
Xavier Soares
Top achievements
Rank 2
answered on 07 Feb 2011, 03:13 PM
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
0
Xavier Soares
Top achievements
Rank 2
answered on 07 Feb 2011, 03:16 PM
Nevermind! Got it
0
Julian Benkov
Telerik team
answered on 10 Feb 2011, 10:15 AM
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.
0
Accepted
erwin
Top achievements
Rank 1
Veteran
answered on 10 Feb 2011, 12:48 PM
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;
}
0
Eric
Top achievements
Rank 1
answered on 20 Oct 2011, 12:03 AM
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



0
Accepted
erwin
Top achievements
Rank 1
Veteran
answered on 20 Oct 2011, 07:06 PM
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

0
Eric
Top achievements
Rank 1
answered on 20 Oct 2011, 07:37 PM
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
0
Mark
Top achievements
Rank 1
answered on 19 Dec 2011, 05:29 AM
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
0
Jeen
Top achievements
Rank 1
answered on 17 Jul 2014, 03:58 PM
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
0
erwin
Top achievements
Rank 1
Veteran
answered on 21 Jul 2014, 10:11 AM
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
0
George
Telerik team
answered on 22 Jul 2014, 09:52 AM
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.
 
0
Jeen
Top achievements
Rank 1
answered on 04 Aug 2014, 09:17 AM
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
Tags
GridView
Asked by
erwin
Top achievements
Rank 1
Veteran
Answers by
Richard Slade
Top achievements
Rank 2
erwin
Top achievements
Rank 1
Veteran
Julian Benkov
Telerik team
Xavier Soares
Top achievements
Rank 2
Eric
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Jeen
Top achievements
Rank 1
George
Telerik team
Share this question
or