Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
More Data grid (6.0 sp4) ADODB
Message
Information générale
Forum:
Visual Basic
Catégorie:
Contrôles ActiveX
Divers
Thread ID:
00468830
Message ID:
00468893
Vues:
13
>How can you access a specific cells. I fell back to my old habits and I've been working with the recordset of the grid but I have been tasked to use the actual grid. I need to get the headers and each row. I do not know in advance cols or rows. My function must accept a datagrid as a byref parameter and then parse through to create a report from the grid... Having never used a grid for much other than display I am in the dark. I have no problems with the ADO recordsource, but I cant depend on record source types ... :(

I hope that you will find something in there:
Option Explicit

Private Sub Command1_Click()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset

    Set cnn = New ADODB.Connection
    cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB"
    cnn.Open
    
    Set rst = New ADODB.Recordset
    rst.CursorLocation = adUseClient
    rst.Open "SELECT OrderID, OrderDate FROM orders", cnn, adOpenStatic, adLockReadOnly
    
    Set DataGrid1.DataSource = rst
    DataGrid1.Refresh
End Sub

Private Sub Command2_Click()
Dim intI As Integer
Dim intJ As Integer

    With DataGrid1
        'Go to top of the grid
        If Not (.DataSource Is Nothing) Then
            If .VisibleRows < .ApproxCount Then
                On Error Resume Next
                Do While True
                    .Scroll 0, -100
                    .FirstRow = 0
                    If Err.Number <> 0 Then Exit Do
                Loop
                On Error GoTo 0
            End If
            If .ApproxCount > 0 Then
                .Col = 0
                .Row = 0
            End If
        End If
    
        'Get headers
        For intI = 0 To .Columns.Count - 1
            MsgBox .Columns(intI).Caption
        Next intI
    
        'Get all lines
        For intI = 0 To .ApproxCount - 1
            For intJ = 0 To .Columns.Count - 1
                MsgBox .Columns(intJ).Text
            Next intJ
            'Incrémente la ligne (ne surtout pas enlever le "On error...")
            On Error Resume Next
            .Row = .Row + 1
            On Error GoTo 0
        Next intI
    End With
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform