Getting the count of Currently viewable rows in a datagrid

N

ntregillus

Hi,

Ok so i have a datagrid which displays a bunch of rows. I want to get
the visible count of rows the datagrid control is currently displaying.

i was using the VisibleRowCount property, but it will only return the
correct value if the number of rows does not exceed the datagrids size
(by this i mean the scroll bars do not appear)

how do i get this value? If i access the table behind, i might not
actually get what i want because a row could be deleted, and i have not
rebound the control, or accepted the change.

Thanks,

Nathan Tregillus
 
G

Guest

By navigating through the datagrid in the watch window, I found that the
datagrid (if bound to a dataset) still has a dataview object you can access,
as long as you have a reference to your dataset:

Dim dvDataView As DataView
dvDataView = DirectCast(grdMyGrid.BindingContext(dsMyDataSet,
"MyTableName").Current, DataRowView).DataView

You can obviously get rid of the directcast (which is just a CType()
alternative). Anyway now that you have a reference to the dataview, you can
simply call dvDataView.Count to get the "visible" row count.

The other option would be to bind your datagrid directly to a dataview
object and keep a reference to it for later use, but I could not do that in
my environment (I lost some other functionality I needed).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top