Count records

  • Thread starter Thread starter Vinnie
  • Start date Start date
V

Vinnie

Is it possible to count the number of records / rows
currently being displayed in a datagrid with a view to
displaying the result and how ?

Cheers Vinnie
 
If you mean what's visible at any time, check out
datagrid.visiblerowcount(), else it's .count() of the
underlying datasource. HTH.
 
You could use something like this but natuarly you need
to call the sub on the form load and on each navigation
click. Also I used this on my full dataset not on what
was currently being displayed in the datadrid I'm not
sure how to re-engineer this for that but maybe you can
figure out yourself if not I'm sure one of the experts
here will throw a bit more light on the subject for you.


\\\
Protected Sub ShowCurrentRecord()

lblRecordNumber.Text = "Record " & _
Me.BindingContext
(DataSetOrders, "Order").Position + 1 & " of " & _
Me.BindingContext
(DataSetOrders, "Order").Count
End Sub
///

Regards Steve
 
ok Vinnie here you go this will display the results your
looking for according to whats being displayed in your
grid at any given moment providing you call the sub at
any point where you anticipate the number of records will
change.

\\\
Protected Sub ShowCurrentRecord()

lblRecordNumber.Text = "Record " & _
Me.OrdersDataGrid.CurrentRowIndex + 1 & " of " & _
Me.OrdersDataGrid.VisibleRowCount

End Sub
///

regards Steve
 
ok sorry

as well as calling the sub when you anticipate that the
number of records you will also need top call it each
time you change record in your datagrid to update the
current record.

The best one I can find for this is the
grids .CurrentCellChanged method this will update your
current record number when click on any of the cells in
the grid it will also update if you tab through the grid

regards steve
 
P.S. If you always navigate the *data*, the datagrid
will take care of itself. That is, rather than worry
about things from the UI perspective (e.g.
CurrentCellChanged, etc.), focus on where you're at in
the data source.

Use the binding context (or better yet, a currency
manager) on the dataset/datatable that's bound to the
grid. When you move through the data in your code (e.g.
you've got a "go next" button that sets
CurrencyManager.Position += 1), the datagrid will keep up
by itself. Likewise, when the user moves around in the
datagrid on his own by changing cells, the currency
manager keeps up, so you can always display "Row
<CurrencyManager.Position> of CurrencyManager.Count>.

As an aside, best book I've seen (intermediate level) on
just such stuff is Murach's VB.NET Database Programming
with ADO.NET.

HTH
 
Back
Top