Function GetListViewValue(ByRef oLV As System.Windows.Forms.ListView, ByVal lRow As Integer, ByVal lCol As Integer, Optional ByVal sEmptyValue As String = "", Optional ByVal sMissingCell As String = "#ERROR#") As String
' oLV : la ListView
' lRow : numéro de ligne. commence 0 = header
' lCol : numéro de colonne. commence à 1
' sEmptyValue : valeur à retourner en cas de cellule vide
' sMissingCell : valeur à retourner en cas d'erreur (cellule n'existe pas)
Dim sRet As String = sMissingCell
With oLV
If (lRow >= 0) And (lCol >= 1) Then
If (lRow <= .Items.Count) And (lCol <= .Columns.Count) Then
sRet = sEmptyValue
If lRow = 0 Then 'header
If .Columns(lCol).Text.Length > 0 Then
sRet = .Columns(lCol).Text
End If
ElseIf lCol = 1 Then '1ère colonne
If .Items(lRow - 1).Text.Length > 0 Then
sRet = .Items(lRow - 1).Text
End If
Else 'les autres colonnes
If .Items(lRow - 1).SubItems(lCol - 1).Text.Length > 0 Then
sRet = .Items(lRow - 1).SubItems(lCol - 1).Text
End If
End If
End If
End If
End With
Return sRet
End Function