• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2965
  • Last Modified:

VB6 DataGrid Going through Rows on Grid errors on last row

I have a bound Datagrid to an Access Db. In this particular case I get
an error when going through the rows to update a particular column.
The "resale" column is a hidden column. If I get a dataset with let's
say 9 rows, this will bomp out on the Datagrid1.Row when it i gets
to 8. This will udpate all rows except the last one. I have tried
For i = 1 To DataGrid1.ApproxCount -1
For i = 0 To DataGrid1.ApproxCount
For i =1 To DataGrid1.ApproxCount

            For i = 0 To DataGrid1.ApproxCount - 1
                DataGrid1.Row = i
                DataGrid1.Columns("resale") = i
                Debug.Print CStr(i) + "  " + DataGrid1.Columns(0).Text
            Next i

I have VB6 SP5 installed. Any help appreciated.
0
Tuftco
Asked:
Tuftco
  • 2
  • 2
1 Solution
 
Michael_DCommented:
Hi Tuftco,

Instead of .ApproxCount property use your recordset's .RecordCount property

Cheers!
0
 
TuftcoAuthor Commented:
Either way, there is exactly 9 records to deal with in this case. What is getting me is that
the Datagrid seems to think that it has one less than what ever I return as a dataset.

0
 
Michael_DCommented:
Dim i As Long
For i = 0 To myRecordset.RecordCount - 1
'For i = 0 To Adodc1.Recordset.RecordCount - 1 'if you are using adoDC component use this  line instead of prev one
    DataGrid1.Row = i
    DataGrid1.Columns("resale") = i
    Debug.Print CStr(i) + "  " + DataGrid1.Columns(0).Text
Next i
0
 
Éric MoreauSenior .Net ConsultantCommented:
I have had problems with that too in the past. It seems that only visible rows are considered!

Try this:

           GridGotoTop

            For i = 0 To DataGrid1.ApproxCount - 1
                DataGrid1.Columns("resale") = i
                Debug.Print CStr(i) + "  " + DataGrid1.Columns(0).Text

           On Error Resume Next
           DataGrid1.Row = DataGrid1.Row + 1 'Set the active row
           On Error GoTo 0

            Next i


Private Sub GridGotoTop()
    With DataGrid1
        If .VisibleRows < .ApproxCount Then
            On Error Resume Next
            Do While .FirstRow <> 1
                .Scroll 0, -10
                .FirstRow = 0
            Loop
            On Error GoTo 0
        End If
        .Col = 0
        .Row = 0
    End With
End Sub
0
 
TuftcoAuthor Commented:
emoreau


Thank You for this answer. At first I didn't see why it works, but after a few trials I understand it.
I even used it go return to the top of the grid after going through the rows and updating
columns and making calculations..

GridGotoTop
With DataGrid1
  .Row = 0
  .Col = 0
End With

Thanks
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now