views:

4344

answers:

3

I have a table with say 1640 items. I set

bindingSource.Filter = "some filter query string";

and most of the rows disappear, leaving, say, 400 rows. I'd like to be able to tell the user "Showing 400 of 1640 items" as they click some textboxes which change the filter string and hence which rows are visible in the dataGridView object (much like iTunes but for medical data, not genres/artists/albums filtering songs).

I tried bindingSource.Count and it is always 1640 no matter what the Filter string is set to (even though many fewer rows are shown as desired). I tried looping over all the rows in dataGridView.Rows and counting only the rows that are Visible, but that still sums to 1640.

Where can I get this information?

Note that I am not using SQL but bindingSource.DataSource is a DataSource from a DataView wrapped around a DataTable (from a dataSet read from XML).

+1  A: 

How about adding the filtered items in a separate DataTable and doing a count on that for the filtered items.

Picflight
+1  A: 

Jared,

I recently had to do this very thing. What worked for me was using the DataGridView.Rows.Count property after I applied the filter.

Are you setting your data source to the DataSource property of the BindingSource or the DataGridView? It should be the BindingSource.

HTH -Jay

Jay Riggs
A: 

I screwed something else up. Jay is right:

dataGridViewCases.Rows.Count

works, as does:

bindingSource.Count
Jared Updike