Jump to content

Detect a check being placed in listview


Recommended Posts

I have a list view and using to build a Windows Profile management tool.

I am trying to detect when a check is placed in it so that I can highlight the row with a color, and preform the reverse when that is un-checked.

Here is what I have so far for the list view portion of the code:

; ###########################################################################
;  Step 7: Display and manage the GUI
; ##########################################################################

; GUI - Create Window and add first row with column names.
GUICreate("Profile Tool", $Width , $Height, -1, -1, -1, $WS_MAXIMIZEBOX)
$ListView = GUICtrlCreateListView("   # |Profile Name        |Last Modified           | Profile Size      | Profile Type    |File Path          |Registry Path", 10, 10, $Width - 10, $Height - 100, -1, $LVS_EX_CHECKBOXES)
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT))
GUISetState(@SW_SHOW)

; GUI - Create a line item for each profiles registry
For $i = 1 To $ProfileRegistry[0] Step 1
    $ListBox = GUICtrlCreateListViewItem(" " & $i & "|" & $ProfileNames[$i] & "|" & $ProfileDates[$i] & "|" & $ProfileSizes[$i] & "|" & $ProfileTypes[$i] & "|" & $ProfilePaths[$i] & "|" & $ProfileRegistry[$i], $ListView)
Next

;Button 1: Deselect All
$DeselectAll_Button = GUICtrlCreateButton("Desect All", 10, 690, 100, 25)

; Button 2: Select All
$SelectAll_Button = GUICtrlCreateButton("Select All", 130, 690, 100, 25)

; Button 3: Select All Students
$SelectStudents_Button = GUICtrlCreateButton("Select All Students", 250, 690, 100, 25)

; Button 4: Select Old Students
$SelectOldStudents_Button = GUICtrlCreateButton("Select Older Students", 420, 690, 100, 25)

GUISetState()

Do
 $msg = GUIGetMsg()
    Select
            Case $msg = $DeselectAll_Button

            For $i = 0 To $ProfileRegistry[0]
                _GUICtrlListView_SetItemChecked($ListView, $i, False)
                GUICtrlSetColor($ListView, 0x000000) ;Normal color
                GUISetState()
            Next

        Case $msg = $SelectAll_Button
            For $i = 0 To $ProfileRegistry[0]
                _GUICtrlListView_SetItemChecked($ListView, $i, True)
                GUICtrlSetColor($ListView, 0xff0000) ;Selected Color
                GUISetState()
            Next

        Case $msg = $SelectStudents_Button
            For $i = 0 To $ProfileRegistry[0]
                If $ProfileTypes[$i] = "Student" Then
                    GUICtrlSetColor($ListView, 0xff0000) ;Selected Color
                    _GUICtrlListView_SetItemChecked($ListView, $i - 1, True)
                EndIf
                GUISetState()
            Next

        Case $msg = $ListView
            MsgBox(0, "listview", "clicked=" & GUICtrlGetState($ListView), 2)
    EndSelect
Until $msg = $GUI_EVENT_CLOSE

EXIT

Thanks in advance!

Edited by aseitz
Link to comment
Share on other sites

  • Moderators

aseitz,

The only way I know how to detect a ListView checkbox being actioned is to look for the $TVN_SELCHANGEDA or $TVN_SELCHANGEDW message within a WM_NOTIFY and then check the current state of the checkbox against what is was before (I use an array to hold the current checkbox states). Look in my ChooseFileFolder UDF (the link is in my sig) for some sample code.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

1 minute ago, Melba23 said:

aseitz,

The only way I know how to detect a ListView checkbox being actioned is to look for the $TVN_SELCHANGEDA or $TVN_SELCHANGEDW message within a WM_NOTIFY and then check the current state of the checkbox against what is was before (I use an array to hold the current checkbox states). Look in my ChooseFileFolder UDF (the link is in my sig) for some sample code.

M23

Thank you! I will a give that a go.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...