Checking ListView items without using Loop

Posted on 2004-11-10
Last Modified: 2013-12-25
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


Question by:Shiju Sasidharan
    LVL 27

    Accepted Solution


    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

    SelectAll ListView1.hwnd, True
    LVL 14

    Author Comment

    by:Shiju Sasidharan

    Thank u Ark
    it works fine


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    VBA Check for Character 9 62
    Paint/Redraw window while dragging 16 46
    Using "ScreenUpdating" 6 36
    VBA filters 2 22
    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now