Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get visible row count of DataGridView after BindingSource.Filter?

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).

like image 929
Jared Updike Avatar asked Feb 04 '09 00:02

Jared Updike


3 Answers

Try this: datagridviewname.Rows.GetRowCount(DataGridViewElementStates.Visible);

like image 93
ThunderGr Avatar answered Sep 27 '22 18:09

ThunderGr


you need just use Count property of your bindingSource...

ExampleBindoneSource.Count()
like image 28
S.Mohamed Mahdi Ahmadian zadeh Avatar answered Sep 27 '22 18:09

S.Mohamed Mahdi Ahmadian zadeh


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

like image 25
Jay Riggs Avatar answered Sep 27 '22 18:09

Jay Riggs