Solved

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

Posted on 2007-03-28
5
185 Views
Last Modified: 2010-04-30
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
0
Comment
Question by:itortu
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:ia2189
ID: 18812028
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
0
 

Author Comment

by:itortu
ID: 18812140
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.
0
 
LVL 3

Accepted Solution

by:
ia2189 earned 500 total points
ID: 18812163
iTotalRows = 1
grdSerialNumber.TextMatrix(iTotalRows - 1, 0) = "Header Row"

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
0
 

Author Comment

by:itortu
ID: 18812217
i am still getting the overflow run time error '6'
0
 

Author Comment

by:itortu
ID: 18812613
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Spell Check in VB6 13 135
how to know if my Checkbox is True in VB6.0? 9 65
VB 6 error 5 in windows 10 but not in XP 7 67
Publisher:   Unknown     VB.exe Application 1 31
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question