[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

Checking ListView items without using Loop

Hi Experts

   i would like to know whether there is any alternative method to Check / Uncheck all the ListItems in a ListView Control rather than using a loop. Will Subclassing can do this ?

Thanks in Advance

;-)
Shiju

0
Shiju Sasidharan
Asked:
Shiju Sasidharan
1 Solution
 
ArkCommented:
Hi

Private Const LVIS_STATEIMAGEMASK As Long = &HF000
Private Const LVIS_UNCHECKED = &H1000
Private Const LVIS_CHECKED = &H2000
Private Const LVIF_STATE = &H8
Private Const LVM_FIRST = &H1000
Private Const LVM_SETITEMSTATE = (LVM_FIRST + 43)

Private Type LV_ITEM
  Mask As Long
  iItem As Long
  iSubItem As Long
  state As Long
  stateMask As Long
  pszText As String
  cchTextMax As Long
  iImage As Long
  lParam As Long
  iIndent As Long
End Type

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Sub SelectAll(hWnd As Long, Sel As Boolean)
  Dim LV As LV_ITEM
  With LV
    .Mask = LVIF_STATE
    .state = IIf(Sel, LVIS_CHECKED, LVIS_UNCHECKED)
    .stateMask = LVIS_STATEIMAGEMASK
  End With
  Call SendMessage(hWnd, LVM_SETITEMSTATE, -1, LV) ' -1=all items
End Sub

'Using:
SelectAll ListView1.hwnd, True
0
 
Shiju SasidharanAuthor Commented:
Hi

Thank u Ark
it works fine

;-)
Shiju
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now