OVH Cloud OVH Cloud

ListView

1 réponse
Avatar
JCM
Bonjour

j'ai cr=E9=E9 une listwiew (dont le code suit) elle=20
fonctionne, mais je ne sais pas comment r=E9cuperer les=20
donn=E9es port=E9es sur les lignes coch=E9es.

qui peut me dire comment faire=20

Private Sub Form_Load()
Me.LVDepAlim.View =3D lvwReport
Set LaListe =3D Me.LVDepAlim
With LVDepAlim.ColumnHeaders
.Add , , "Code", 1200
.Add , , "Libell=E9", 5000
.Add , , "Montant", 2000
End With
LVDepAlim.GridLines =3D True 'une ligne horizontale s=E9pare=20
chaque ligne
LVDepAlim.FullRowSelect =3D True 'click =3D surligne
LVDepAlim.Checkboxes =3D True 'une case =E0 cocher sur chaque=20
ligne

With ADOcn
.Provider =3D "Microsoft.Jet.OLEDB.4.0"
.ConnectionString =3D "Data Source=3D" & Chemin
.CursorLocation =3D adUseClient
.Open
End With

Set ADOlist =3D New ADODB.Recordset
With ADOlist
.ActiveConnection =3D ADOcn
.CursorType =3D adOpenDynamic
.Open "Select * from depenseACFCI2001"
End With

While Not ADOlist.EOF
Set LaLigne =3D LVDepAlim.ListItems.Add(, , CStr(ADOlist!
IDdepense))
I =3D I + 1
LaLigne.Tag =3D "ListItem " & I
If Not IsNull(ADOlist!libelle) Then
LaLigne.SubItems(1) =3D CStr(ADOlist!libelle)
End If
If Not IsNull(ADOlist!montant) Then
LaLigne.SubItems(2) =3D (ADOlist!montant)
End If
ADOlist.MoveNext
Wend
End Sub

Merci de vos r=E9ponses
Cordialement
JCM

1 réponse

Avatar
François Picalausa
Bonjour/soir,

Une technique consiste à boucler sur tous les éléments et tester s'ils sont
cochés:
Dim objListItem As ListItem

For Each objListItem In ListView1.ListItems
If objListItem.Checked Then
'Traitement
Debug.Print objListItem.ListSubItems(1).Text
Debug.Print objListItem.ListSubItems(2).Text
End If
Next objListItem

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


JCM wrote:
Bonjour

j'ai créé une listwiew (dont le code suit) elle
fonctionne, mais je ne sais pas comment récuperer les
données portées sur les lignes cochées.

qui peut me dire comment faire

Private Sub Form_Load()
Me.LVDepAlim.View = lvwReport
Set LaListe = Me.LVDepAlim
With LVDepAlim.ColumnHeaders
.Add , , "Code", 1200
.Add , , "Libellé", 5000
.Add , , "Montant", 2000
End With
LVDepAlim.GridLines = True 'une ligne horizontale sépare
chaque ligne
LVDepAlim.FullRowSelect = True 'click = surligne
LVDepAlim.Checkboxes = True 'une case à cocher sur chaque
ligne

With ADOcn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & Chemin
.CursorLocation = adUseClient
.Open
End With

Set ADOlist = New ADODB.Recordset
With ADOlist
.ActiveConnection = ADOcn
.CursorType = adOpenDynamic
.Open "Select * from depenseACFCI2001"
End With

While Not ADOlist.EOF
Set LaLigne = LVDepAlim.ListItems.Add(, , CStr(ADOlist!
IDdepense))
I = I + 1
LaLigne.Tag = "ListItem " & I
If Not IsNull(ADOlist!libelle) Then
LaLigne.SubItems(1) = CStr(ADOlist!libelle)
End If
If Not IsNull(ADOlist!montant) Then
LaLigne.SubItems(2) = (ADOlist!montant)
End If
ADOlist.MoveNext
Wend
End Sub

Merci de vos réponses
Cordialement
JCM