how to count the total rows in datagrid


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: how to count the total rows in datagrid

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Posts
    2

    Question how to count the total rows in datagrid

    hi,

    please help..
    i need to know how to count the total rows in datagrid. only i was able to determine how to determine the total columns (datagrid1.columns.count). Can anyone would help me?



    thanks n advance..


    relan

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Is the DataGrid bound to a recordset? If so, the number of rows is equal to the recordset's .RecordCount property.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jan 2006
    Posts
    2
    phil webber,

    thanks a lot for helping me. Also i will ask again a favor from you.

    Now i get the total row count in datagrid. For example i have 17 rows and each row have 18 columns with values on each. how do i read all the values in each rows.
    by the way this is my code in reading the values in each rows but i get an error when i reach reading at row 15.

    thanks in advance and god bless..

    --------------------------------------------------------------------------
    Private Sub Command1_Click()
    Dim date_sub As String, computer As String, printer As String, username As String, document As String
    Dim status As String, pages As String, bytes As String
    Dim total_rows As String
    Dim i As Integer

    total_rows = Read_Text_File.RecordCount
    For i = 0 To total_rows
    dgdata.row = i
    dgdata.Col = 8
    date_sub = dgdata.Text
    dgdata.row = i
    dgdata.Col = 2
    computer = dgdata.Text
    dgdata.row = i
    dgdata.Col = 1
    printer = dgdata.Text
    dgdata.row = i
    dgdata.Col = 3
    username = dgdata.Text
    dgdata.row = i
    dgdata.Col = 4
    document = dgdata.Text
    dgdata.row = i
    dgdata.Col = 13
    status = dgdata.Text
    dgdata.row = i
    dgdata.Col = 5
    pages = dgdata.Text
    dgdata.row = i
    dgdata.Col = 9
    bytes = dgdata.Text
    If pages = "0" Then
    pages = "unknown"
    End If

    MsgBox date_sub & ": " & computer & ": " & printer & ": " & username & ": " & document & ": " & status & ": " & pages & ": " & bytes

    Next

    End Sub
    --------------------------------------------------------------------------

  4. #4
    Join Date
    Aug 2014
    Posts
    5
    The Grid's Row method is 0 based. So the last Row is Recordcount -1
    Therefore use: For i = 0 To (total_rows -1)

    (Also, never use the ApproxCount for something like this. As the name says: It is an approximate count, and may not always be the actual count with large recordsets.)

    Quote Originally Posted by relan8 View Post
    phil webber,

    thanks a lot for helping me. Also i will ask again a favor from you.

    Now i get the total row count in datagrid. For example i have 17 rows and each row have 18 columns with values on each. how do i read all the values in each rows.
    by the way this is my code in reading the values in each rows but i get an error when i reach reading at row 15.

    thanks in advance and god bless..

    --------------------------------------------------------------------------
    Private Sub Command1_Click()
    Dim date_sub As String, computer As String, printer As String, username As String, document As String
    Dim status As String, pages As String, bytes As String
    Dim total_rows As String
    Dim i As Integer

    total_rows = Read_Text_File.RecordCount
    For i = 0 To total_rows
    dgdata.row = i
    dgdata.Col = 8
    date_sub = dgdata.Text
    dgdata.row = i
    dgdata.Col = 2
    computer = dgdata.Text
    dgdata.row = i
    dgdata.Col = 1
    printer = dgdata.Text
    dgdata.row = i
    dgdata.Col = 3
    username = dgdata.Text
    dgdata.row = i
    dgdata.Col = 4
    document = dgdata.Text
    dgdata.row = i
    dgdata.Col = 13
    status = dgdata.Text
    dgdata.row = i
    dgdata.Col = 5
    pages = dgdata.Text
    dgdata.row = i
    dgdata.Col = 9
    bytes = dgdata.Text
    If pages = "0" Then
    pages = "unknown"
    End If

    MsgBox date_sub & ": " & computer & ": " & printer & ": " & username & ": " & document & ": " & status & ": " & pages & ": " & bytes

    Next

    End Sub
    --------------------------------------------------------------------------

  5. #5
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    What data type is Read_Text_File? If it's a recordset, you can (and should) read the data values from it, rather than from the grid. The recordset contains the data; the grid is only to display it.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  6. #6
    Join Date
    Sep 2013
    Posts
    1
    debug.print DataGrid1.ApproxCount
    This would display the row count of the Datagrid1

Similar Threads

  1. Delete Rows from DataGrid
    By software_develo in forum .NET
    Replies: 0
    Last Post: 01-01-2006, 11:24 PM
  2. Add or delete rows from the dataGrid
    By software_develo in forum .NET
    Replies: 1
    Last Post: 12-27-2005, 06:28 AM
  3. need to return total record count, but here is the trick...
    By barbarosa80503 in forum VB Classic
    Replies: 2
    Last Post: 10-28-2005, 04:33 PM
  4. How to count rows in DBgrid/DataGrid
    By Michael L in forum VB Classic
    Replies: 2
    Last Post: 11-17-2000, 03:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center