Link to home
Start Free TrialLog in
Avatar of itortu
itortuFlag for United States of America

asked on

ad rows to grid dynamically. not displaying the first row. URGENT PLEASE!

i need to know what i am doing wrong with the way i am adding rows to my grid.

the rows are being added, but the first row is been omitted, i think due to the way i set the header row.

So if i have serial number:

001
002
003
004
005

the grid only shows:

002
003
004
005

any help is greatly appreciated, thank you.

Const g_COL_SERIAL_NO = 0

    If Not rstSelect Is Nothing Then
        If Not rstSelect.BOF And Not rstSelect.EOF Then
            Do While Not rstSelect.EOF
                r = r + 1
                grdSerialNumber.Rows = r + 1
                For c = 0 To rstSelect.RecordCount - 1
                        strSerialNumber = rstSelect![serial_number]
                        grdSerialNumber.FormatString = "Serial No"
                        grdSerialNumber.ColWidth(g_COL_SERIAL_NO) = 1335
                        grdSerialNumber.TextMatrix(totalRecs, 0) = strSerialNumber
                       
                Next c
                rstSelect.MoveNext
                totalRecs = totalRecs + 1
            Loop
        Else
            ' Do nothing
        End If
       
    End If
Avatar of ia2189
ia2189

I'm not exactly sure what all your variables are, or why you're needing a for...next loop inside your do...while loop, but below works fine for me.  You can set iTotalRows to one initially if you want a header row.

iTotalRows = 0

If Not rstSelect Is Nothing Then
   If Not rstSelect.BOF And Not rstSelect.EOF Then
      Do While Not rstSelect.EOF
         iTotalRows = iTotalRows + 1
         grdSerialNumber.Rows = iTotalRows
         grdSerialNumber.TextMatrix(iTotalRows - 1, 0) = rstSelect("serial_number")
      Loop
   End If
End If
Avatar of itortu

ASKER

i am getting now a overflow error using your code snippet.

how can then the code be with the header row in it?

thank you.
ASKER CERTIFIED SOLUTION
Avatar of ia2189
ia2189

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itortu

ASKER

i am still getting the overflow run time error '6'
Avatar of itortu

ASKER

this how i got it to work.

Const g_COL_SERIAL_NO = 0
Dim r As Integer

    grdSerialNumber.Rows = 1
    grdSerialNumber.TextMatrix(r, 0) = "Serial No"
   
    If Not rstSelect Is Nothing Then
        If Not rstSelect.BOF And Not rstSelect.EOF Then
            With grdSerialNumber
                While Not rstSelect.EOF
                    r = r + 1
                    .Rows = .Rows + 1
                    .ColWidth(g_COL_SERIAL_NO) = 1335
                    .TextMatrix(r, g_COL_SERIAL_NO) = rstSelect![serial_number]
                    rstSelect.MoveNext
                Wend
            End With
        Else
            ' Do nothing
        End If
    End If