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

count filtered rows

4 Answers 549 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jens
Top achievements
Rank 2
Jens asked on 18 Nov 2011, 01:26 PM
Hi,

I have a problem counting the filtered rows, e.g. I have 50 rows in the grid's DataSource table but after applying a filter, only 10 rows are shown in the grid, so what I want to count is just these 10 row (version 2011.2.11.712).

The problem has come up already in this forum and I tried the following:

1.grid.Items.ItemCount: results in error as the grid does not have the property Items.
2.grid.MasterTemplate.ChildRows.Count: always returns just 1
3. looping through grid.Rows and checking the IsVisible property or each row: is true for all 50 rows
4. comparing the underlying table rows with grid.Rows[i].DataBoundItem as described in another thread here: does not do the trick either.

What am I missing here? Hope you can help me with this, thanks a lot in advance

 

4 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 21 Nov 2011, 05:08 PM
Hi Jens,

Thank you for contacting us.

You can get the currently displayed rows in the RadGridView by accessing the ChildRows property. This would give you the rows left after the filtering. Here is a code snippet which demonstrates this:

this.radGridView1.ChildRows.Count

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

I hope this will help. If you need further assistance do not hesitate to write back. Greetings,
Ivan Petrov
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Renate
Top achievements
Rank 1
answered on 21 Nov 2011, 05:53 PM
Hi Ivan,

thank you very much!
0
erwin
Top achievements
Rank 1
Veteran
answered on 21 Nov 2011, 10:30 PM
Jens,

be aware that if you allow grouping on the grid, you have to count ChildRows.Count recoursively for all group headers.
see my post about counting visible rows in this forum. 

Regards
Erwin
0
Jens
Top achievements
Rank 2
answered on 24 Nov 2011, 11:43 AM
Hi erwin,

sorry to come back so late - found your recursive method and it works just great, thank you!
Tags
GridView
Asked by
Jens
Top achievements
Rank 2
Answers by
Ivan Petrov
Telerik team
Renate
Top achievements
Rank 1
erwin
Top achievements
Rank 1
Veteran
Jens
Top achievements
Rank 2
Share this question
or