Author : Dipen Anovadia
Date Submitted : 3/29/2006
Category : Microsoft Controls
Compatibility : VB 6,VB 5
This code has been accessed 3572 times.
Task : Inverses the selection in either ListBox or ListView
Declarations
Code
'********************************************************
'eMail: dippu75@hotmail.com [Errors, Feedbacks, etc.]
'* **************************************************** *
' Inverses the selection in either ListBox OR ListView *
'* **************************************************** *
'IN:
' lo - ListBox OR ListView OBJECT reference
'OUT:
' lOUT_ERROR - Gives error number if occured, else 0
'********************************************************
Public Sub InverseSelection(lo As Object, Optional lOUT_ERROR As Long = 0)
On Error Goto errIS
If Not (TypeOf lo Is ListBox Or _
TypeOf lo Is ListView) Then
Exit Sub
End If
Dim l As Long, lCount As Long
lCount = IIf(TypeOf lo Is ListView, _
lo.ListItems.Count, lo.ListCount) - 1
If lCount <= 0 Then Exit Sub
For l = 0 To lCount
If TypeOf lo Is ListView Then
lo.ListItems(l).Checked = Not lv.ListItems(l).Checked
Else
lo.Selected = Not lo.Selected
End If
Next l
Exit Sub
errIS:
lOUT_ERROR = Err.Number
Err.Clear
End Sub