L1.ListItems.Clear

Dim li1 As ListItem

Set li1 = LV1.ListItems.Add()

While Not (rs.EOF)

li1.Text = rs(0)

rs.MoveNext

Wend

rs.Close

Voici une sub qui te permettra d'initialiser ton listview

Private Sub Init_ListviewDv()
 Rem=====pour mettre à jour le listview =======
With LviewDv
.ListItems.Clear
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "Nop", .Width / 15, lvwColumnLeft 'Colonne(C0)
.ColumnHeaders.Add , , "Champ1 de ta base ", .Width / 7, lvwColumnCenter 'C1
.ColumnHeaders.Add , , "Champ2...", .Width / 3, lvwColumnLeft 'C2
.ColumnHeaders.Add , , "Champ3...", .Width / 6, lvwColumnRight 'C3
.ColumnHeaders.Add , , "Champ4...", .Width / 6, lvwColumnRight 'C4
.ColumnHeaders.Add , , "Champ5....", .Width / 7, lvwColumnRight 'C5
.ColumnHeaders.Add , , "Observation", .Width / 2, lvwColumnLeft 'C10
.View = lvwReport
.Gridlines = False
End With
End Sub

une seconde sub qui te permettre de charger les éléments de la base de donnée dans le listview pour affichage===

`Private Sub MajLviewDv()
'rem mise à jour du listview
`'Déclare une variable pour ajouter des objets ListItem.`
Dim itmx As ListItem
    ' Gestion erreur
On Error Resume Next
' Ajout des colonnes à la listview
Init_ListviewDv
' Préparation de la requêtes
RsqlDv = "SELECT * FROM Devise " 'where [Type_Payement]='" & LstEnc & "'"
'Execution requête avec paramètre recordset via CnxAdo
RDv.CursorLocation = adUseClient
RDv.Open RsqlDv, CnxDv, adOpenDynamic, adLockPessimistic
' on est toujours sous la gestion d'erreur
'Execute_Sql = (err.Number = 0)
'If err.Number Then err.Clear
' nbr enregistrement base
'Info_Nbr_record_base = RstAdo.RecordCount
' Vérifie si la base n'est pas vide
'If Info_Nbr_record_base = 0 Then
'MsgBox "La base de données est vide !", vbExclamation Or vbOKOnly, "Information utilisateur"
'Else
' Remplie la listview via la base
While Not RDv.EOF
   Set itmx = LviewDv.ListItems.Add(, , CStr(RDv!NumOP))
   itmx.SubItems(1) = RDv!DateOpera
   itmx.SubItems(2) = RDv!LibeleOpera
   itmx.SubItems(3) = Format(RDv!MEntree, "# ##0.00")
   itmx.SubItems(4) = Format(RDv!MSortie, "# ##0.00")
   itmx.SubItems(5) = Format(RDv!MSolde, "# ##0.00")
   itmx.SubItems(6) = RDv!Commentaire
   ' Passe à l'enregistrement suivant.
   RDv.MoveNext
Wend
'Calcul Somme Colonne Montant_Réglé de Listview
Dim k As Integer
Dim Total1 As Currency
Dim Total2 As Currency

With LviewDv
For k = 1 To .ListItems.Count
  Total1 = Total1 + .ListItems(k).ListSubItems(3).Text
  Total2 = Total2 + .ListItems(k).ListSubItems(4).Text
Next
  Txbox(6).Value = Format(Total1 - Total2, "# ##0.00 DA")
End With
'libére l'object
Set RDv = Nothing
Set CnxDv = Nothing
'On sort
Exit Sub
Aff_Err:
'Type erreur
 MsgBox Err.Description, vbExclamation Or vbOKOnly, "Information utilisateur"
Err.Clear
End Sub`

@alfadz, please see our posting rules. We need to keep it in English. Thanx for your post though...

@ponnu, the below part of alfadz's code will do the trick -

Private Sub Init_ListviewDv()
 Rem=====pour mettre à jour le listview =======
With LviewDv
.ListItems.Clear
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "Nop", .Width / 15, lvwColumnLeft 'Colonne(C0)
.ColumnHeaders.Add , , "Champ1 de ta base ", .Width / 7, lvwColumnCenter 'C1
.ColumnHeaders.Add , , "Champ2...", .Width / 3, lvwColumnLeft 'C2
.ColumnHeaders.Add , , "Champ3...", .Width / 6, lvwColumnRight 'C3
.ColumnHeaders.Add , , "Champ4...", .Width / 6, lvwColumnRight 'C4
.ColumnHeaders.Add , , "Champ5....", .Width / 7, lvwColumnRight 'C5
.ColumnHeaders.Add , , "Observation", .Width / 2, lvwColumnLeft 'C10
.View = lvwReport
.Gridlines = False
End With
End Sub

Andre shown how to add header and display it in report style.
Below is how to display data into listview using access and adodb.
Modified as you need and show to us how it work..

Private Sub ShowData()
    Dim con As ADODB.Connection
    Set con = New ADODB.Connection
    Dim rsShow As ADODB.Recordset
    Set rsShow = New ADODB.Recordset
    con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\project.MDB;Persist Security Info=False"

    rsShow.Open "SELECT * FROM Student ", con, adOpenStatic, adLockOptimistic
    ListView1.ListItems.Clear

    While Not rsShow.EOF
        Set View = ListView1.ListItems.Add
        View.Text = rsShow!ID
        View.SubItems(1) = rsShow!LastName
        View.SubItems(2) = rsShow!FirstName
        View.SubItems(3) = rsShow!MiddleName
        View.SubItems(4) = rsShow!Age
        View.SubItems(5) = rsShow!Sex
        'and soon
        rsShow.MoveNext
    Wend
    rsShow.Close
    con.Close
End Sub

You can try this code this is tested and working from me.

Dim DB As New ADODB.Connection
Dim RS As New ADODB.Recordset
Dim path as String

path = "\Database.mdb"
DB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & path

Dim x As Integer

    ListView1.ListItems.Clear

            RS.Open "Table", DB, 3, 3

                Do Until RS.EOF
                    Set List = Listview1.ListItems.Add(, , RS(0), , 1)
                        For x = 1 To 3 'if you have 4 fields in the Access like (ID,Fname,Mname,Lname) if you have more than 4 fields like 5 fields just add 1 to 4
                            List.SubItems(x) = RS(x)
                        Next x
                    RS.MoveNext
                Loop
            Set RS = Nothing
        DB.Close: Set DB = Nothing
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.