Results 1 to 7 of 7

Thread: How to loop data from Recordset into DataGrid

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    138

    How to loop data from Recordset into DataGrid

    instead of setting the DataSource to the recordset, I would like to loop the data. I was previously used Sheridan Data Widgets (3rd party control) to populate and view data from a database and it was very easy using "DataGrid.AddItem" in DataGridView

    May I know how do I do that using DataGrid?

    Thank you in advance for any replies

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to loop data from Recordset into DataGrid

    I believe the DataGrid is a bound control, so I think you need to use the DataSource (I'm not completely sure as I've never used this control.)

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: How to loop data from Recordset into DataGrid

    Since DatGrid is a bound control you will have to loop through underlying recordset object.
    In order for this code to work Adodc1.Recordset.CursorLocation must be set to adUseClient before your populate recordset.
    Code:
    Private Sub Command3_Click()
    Dim i As Long
    
        For i = 0 To Adodc1.Recordset.RecordCount - 1
            '...
        Next i
    
    End Sub
    Also, you mentioned the DataGridView name which is default name for a datagrid control in Visual Basic 2005; so, what version of VB do you actually use?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    138

    Re: How to loop data from Recordset into DataGrid

    Actually the datagrid control that I normally use is SSDBGrid and not DataGridView. SSDBGrid is one of few controls from Sheridan. I am coding in VB6 by the way. Normally with SSDBGrid this is how I would do


    Code:
    str = "SELECT * FROM tblStkGrpCd"
    Rst.Open str, POConn, adOpenKeyset, adLockOptimistic
    With SSDBCStkGrpCd
    .RemoveAll
    Do While Not Rst.EOF
        .AddItem Trim(Rst.Fields(0)) & vbTab & Trim(Rst.Fields(1))
        Rst.MoveNext
    Loop
    End With
    Rst.Close
    Set Rst = Nothing
    How do I do this part in standard VB6 DataGrid?

    Code:
    Do While Not Rst.EOF
        .AddItem Trim(Rst.Fields(0)) & vbTab & Trim(Rst.Fields(1))
        Rst.MoveNext
    Loop

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to loop data from Recordset into DataGrid

    I would suggest consulting the SSDBGrid documentation

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: How to loop data from Recordset into DataGrid

    How do I do this part in standard VB6 DataGrid?
    You can't. The DataGrid does not support an "Unbound" mode. Use the MSFlexGrid or the MSHFlexGrid.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    138

    Re: How to loop data from Recordset into DataGrid

    Quote Originally Posted by brucevde
    You can't. The DataGrid does not support an "Unbound" mode. Use the MSFlexGrid or the MSHFlexGrid.
    I guess that means there is no way for me to manually pump in data through coding?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width