Solved

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

Posted on 2007-03-28
5
173 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
i am still getting the overflow run time error '6'
0
 

Author Comment

by:itortu
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 …
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now