Utilisation des case à cocher

Pour gérer les cases à cocher dans les listview, j'ai crée deux fonctions. La première permet de savoir si un élément est coché, la deuxièmre permet de changer l'état de ce même élément.

 

Function ListViewEstCoche(ByVal MaListView As Long, ByVal Index As Integer) As Boolean

 

Dim lI As Long

Dim lR As Long

lR = SendMessage(MaListView, LVM_GETITEMSTATE, Index, LVIS_STATEIMAGEMASK)

If (lR And &H2000&) = &H2000& Then

ListViewEstCoche = True

Else

ListViewEstCoche = False

End If

 

End Function

Sub ListViewCoche(ByVal MaListView As Long, ByVal Index As Integer)

 

Dim lR As Long

Dim tLV As LVITEM

tLV.iItem = Index

tLV.mask = LVIF_STATE

tLV.stateMask = &H3000&

 

If (SendMessage(MaListView, LVM_GETITEMSTATE, Index, LVIS_STATEIMAGEMASK) And &H2000&) = &H2000& Then

' uncheck

tLV.state = &H1000&

Else

' check

tLV.state = &H2000&

End If

lR = SendMessage(MaListView, LVM_SETITEMSTATE, Index, tLV)

 

End Sub