Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-03-28
5
Medium Priority
?
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

670 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