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

count filtered rows in group

1 Answer 133 Views
GridView
This is a migrated thread and some comments may be shown as answers.
AJing
Top achievements
Rank 1
AJing asked on 30 Nov 2011, 02:06 AM
Hi:
  Is there a way of counting the visible rows after applying a filter or multiple filter and a group or many group?
  eg: There is a group template by Age column and I apply a filter in city column. How can I count the filtered rows?
   
   Our code as follows:
  radGridView_Filtered(.......)
{
    label1.Text= radGridView.MatserTemplate.ChildRows.Where(o=>o.City='NanJing').Count;
}
   
If there is only filter ,the label1's text display filtered rows .But if there is a group ,the label1's text display zero.
I want the label1's text display filtered rows .

Greeting
Look forward to you
AJing

1 Answer, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 02 Dec 2011, 03:12 PM
Hi Ajing,

The ChildRows collection is hierarchical structure and in your case in order to find only the filtered rows, you must count only the data rows. You can use this simple implementation:

private int GetDataRowCount(GridViewChildRowCollection collection)
{
    int count = 0;
 
    foreach (GridViewRowInfo row in collection)
    {
        if (row is GridViewDataRowInfo)
        {
            count++;
        }
        else
        {
            count += GetDataRowCount(row.ChildRows);
        }
    }
 
    return count;
}

For additional information about the ChildRows collection, please refer to this article.

If you have other questions, do not hesitate to contact me again.

Greetings,
Julian Benkov
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

Tags
GridView
Asked by
AJing
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Share this question
or