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).
Try this: datagridviewname.Rows.GetRowCount(DataGridViewElementStates.Visible);
you need just use Count property of your bindingSource...
ExampleBindoneSource.Count()
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With