Solved

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

Posted on 2007-03-28
5
189 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 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

617 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