Newsgroup: it.comp.lang.visual-basic
Titolo: Filling DBGrid Fields as you process Data?

Hello All,
   I am new at using the DBGrid and am having problems getting it to
work as I would like it to.  Basically I have a function that contains
a loop and I create the fields as I go.  The reason for this is that I
am checking for duplicate part numbers and if there is a duplicate, I
need to concatenate all of the Reference Designators into one field. 
I am doing this with a Do Loop.  I have this all working, but can not
figure out how to populate the DBGrid with the results.  Can someone
help me with this?  The code is below, but does not work properly, it
just pills in the last one, the rest remain empty and I am using
Debug.print to show that it should be filling in the grid.
Thanks!
Grant Griffith
Private Sub optTop_Click()
    Dim ControlData As Recordset
    Dim Index As Integer
    Dim IndexStr As String
    Dim strSQL      As String
    Dim Database1 As String
    Dim Data As Database
    Dim tmpLabel, strPartLabel, strDescription, strRefDesignator As
String
    Dim intQty As Integer
 
    lblBOM.Caption = "TOP BOM"
    Database1 = "D:\baxter\VBPCBP.mdc"
 
    ' Open database.
    Set Data = OpenDatabase(Database1, False, False)
    Index = 0
    strSQL = "Select PartLabel, Description, RefDesignator " & _
                "From TComp Inner Join TPartNumber " & _
                "On TComp.PartNumberID = TPartNumber.PartNumberID " &
_
                "Where Side = 'TOP' AND (PartLabel <> '(null)') " & _
                "Order By PartLabel, RefDesignator"
    Set ControlData = Data.OpenRecordset(strSQL)
    tmpLabel = ""
    Index = 0
    dbgBom.ClearFields
    Do Until ControlData.EOF
        If ControlData("PartLabel") <> tmpLabel Then
            If tmpLabel <> "" Then
                dbgBom.Row = Index
                dbgBom.Columns("Item Number").Text = Index + 1
                dbgBom.Columns("Qty").Text = intQty
                dbgBom.Columns("PartLabel").Text = strPartLabel
                dbgBom.Columns("Description").Text = strDescription
                dbgBom.Columns("RefDesignator").Text =
strRefDesignator
                Debug.Print "Row: " & Index & ") " & intQty & ", " &
strPartLabel & ", " & strDescription & ", " & strRefDesignator
                Index = Index + 1
            End If
            strPartLabel = ControlData("PartLabel")
            strDescription = ControlData("Description")
            strRefDesignator = ControlData("RefDesignator")
            tmpLabel = ControlData("PartLabel")
            intQty = 1
        Else
            intQty = intQty + 1
            strRefDesignator = strRefDesignator & "," &
ControlData("RefDesignator")
        End If
 
        ControlData.MoveNext
    Loop
    ControlData.Close
    Data.Close
 
    dbgBom.Visible = True
End Sub

 Debug.print to show that it should be filling in the grid.
Under VB5.0 the DBGrid runs only in binding mode: there is no way to
populate it row by row coding. With the VB6 DBGrid you can also use it in
unbinding mode and so solve your problem (see the Add method).
Be careful with binding a DBGrid, because if you cause some upgrade to the
data in your database with a recordset different form the one you used to
populate the grid, in some cases you cannot see your modifies into the grid.
Hoping my bad english can help,
bye
Carlo.

 populate the grid, in some cases you cannot see your modifies into the
grid.
methods .refreh, .rebind.

 methods .refreh, .rebind.
Unfortunately not! If you write the data with a recordset different from the
one bounded to the grid (I'm speaking about the data control) the methods
you suggests don't work correctly. Try it yourself!...
Bye,
Carlo.

 you suggests don't work correctly. Try it yourself!...
as it's the vb5 dbgrid and not the ado datagrid, we're talking about dao,
arent we.
can you post some sample code please ?
tnx, andrea