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
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
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
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
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.
Julian Benkov
the Telerik team
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
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
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;
}
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
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
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
int rowCount = myGridView.ChildRows.Count(row => row.IsVisible);
works with both filters applied and if you manually hide rows by setting row.IsVisible
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
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
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
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