Re: Number of rows in a datagrid




"PaulNaude" <PaulNaude@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E2438D9F-3085-4780-B67D-F9D48592410D@xxxxxxxxxxxxxxxx
>I discovered the hard way that the property "VisibleRowCount" of a datagrid
> is ONLY that, the number of visible rows, NOT the number of populated rows
> in
> the datagrid.
>
> I need the number of populated rows (i.e. the number of records the user
> has
> access to by scrolling to the end of the list).
>
> I can't get it from the table since the datagrid is filtered.
>
> Should I actually run a for next loop to count the rows, or even create a
> datatable from the datagrid?
>
> I am sure there must be a short cut!

Obtain a reference to the recordset object to which the grid is bound, and
query its RecordCount property.

' assumes datagrid object is named 'Grid'
'
Dim rs As ADODB.Recordset
Dim obj As Object
Set obj = Grid.DataSource
If (Not IsEmpty(Grid.DataMember)) And (Grid.DataMember <> "") Then
Set rs = obj.DataSource
Else
Set rs = obj
End If

Dim NumOfRowsInGrid
NumOfRowsInGrid = rs.RecordCount
' Don't close the recordset, it's a reference to the one to which the
grid is bound
Set rs = Nothing


-Mark



.



Relevant Pages

  • Re: Select query with parameters
    ... Dim rsPatient As ADODB.Recordset ... I am using the following code to populate the datagrid: ... When you Open a recordset you pass an SQL query statement as a string. ...
    (microsoft.public.vb.database.ado)
  • Re: DataGrid not showing programmatic changes
    ... It's been awhile since I've used the DataEnvironment... ... The DataGrid is usually bound to a Data control which in turn ... rsCashbook is a recordset of that Connection with a source of SELECT * FROM ...
    (microsoft.public.vb.general.discussion)
  • Re: MSHFlexGrid aktualisieren
    ... Das MSHFlexgrid hat keine permanente Verbindung zu Deinem Recordset. ... Das DataGrid verwaltet keinen eigenen ... auch automatisch der neue Datensatz zur aktuellen Zeile ... Private Sub Form_Load ...
    (microsoft.public.de.vb.datenbank)
  • Re: Need example of using ADO DataControl and DataGrid control - V
    ... Data appears in the DataGrid just fine. ... > ' Create connection string to access the database ... > ' Bind the recordset to the data grid. ... > Private Sub Command1_Click ...
    (microsoft.public.vb.database.ado)
  • Re: Große Listen mit Bildern
    ... > Einlesens der Daten ins Recordset wird dann in der Ereignisprozedur ... Auch habe ich keine Möglichkeit gefunden, Symbole in der Datagrid ... Mit Optimierung dauer es bei mir ca. 29 Sek. ...
    (microsoft.public.de.vb.datenbank)