Jump to content

ListView with Checkboxes, Disable/Enable


Recommended Posts

Hello,

I have a ListView with Checkboxes. Is it possible to deactivate some Items? The GuiCtrlSetState doesn't work. Maybe _GUICtrlListView_SetItemState but I don't know. Any idea?

#include <WindowsConstants.au3>
#include <GUIListView.au3>
$GUI = GUICreate("GUI", 600, 300)
$ListView = GUICtrlCreateListView("Test", 10, 10, 580, 280, $WS_BORDER, $LVS_EX_FULLROWSELECT + $LVS_EX_CHECKBOXES)
_GUICtrlListView_SetColumnWidth($ListView, 0, $LVSCW_AUTOSIZE_USEHEADER)


Local $aTest[5] = ["test1", "test2", "test3", "test4", "test5"]
For $i = 0 To 4
    GUICtrlCreateListViewItem($aTest[$i], $ListView)
    GUICtrlSetState(-1, $GUI_DISABLE) ; <-- no change :(
Next

GUISetState(@SW_SHOW)
While True
    $msg = GUIGetMsg()
    Switch $msg
        Case - 3
            Exit
    EndSwitch
WEnd

Thanks,

aquila

Link to comment
Share on other sites

I don't think that there is an official way. You could try this workaround.

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>

$GUI = GUICreate("GUI", 600, 300)
$ListView = GUICtrlCreateListView("Test", 10, 10, 580, 280, $WS_BORDER, $LVS_EX_FULLROWSELECT + $LVS_EX_CHECKBOXES)

Local $aTest[2][5] = [["test1", "test2", "test3", "not checkable", "test5"]]
For $i = 0 To 4
    $aTest[1][$i] = GUICtrlCreateListViewItem($aTest[0][$i], $ListView)
Next

_GUICtrlListView_SetColumnWidth($ListView, 0, $LVSCW_AUTOSIZE_USEHEADER)

GUISetState(@SW_SHOW)

;~ While True
;~  $msg = GUIGetMsg()
;~  Switch $msg
;~   Case - 3
;~          Exit
;~   Case $aTest[1][3]
;~    GUICtrlSetState($msg, $GUI_UNCHECKED)
;~  EndSwitch
;~ WEnd

;or better
While True
    $msg = GUIGetMsg()
    Switch $msg
  Case - 3
            Exit
 EndSwitch
 GUICtrlSetState($aTest[1][3], $GUI_UNCHECKED)
WEnd

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

  • 4 years later...

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>

$GUI = GUICreate("GUI", 600, 300)
$ListView = GUICtrlCreateListView("Test", 10, 10, 580, 280, $WS_BORDER, $LVS_EX_FULLROWSELECT + $LVS_EX_CHECKBOXES)

Local $aTest[2][5] = [["test1", "test2", "test3", "not checkable", "test5"]]
For $i = 0 To 4
    $aTest[1][$i] = GUICtrlCreateListViewItem($aTest[0][$i], $ListView)
Next

_GUICtrlListView_SetColumnWidth($ListView, 0, $LVSCW_AUTOSIZE_USEHEADER)

GUISetState(@SW_SHOW)


While True
    $msg = GUIGetMsg()
    Switch $msg
  Case - 3
            Exit
 EndSwitch
 GUICtrlSetState($aTest[1][3], $GUI_UNCHECKED)
 ;GUICtrlSetBkColor($aTest[1][3],0xF8F8FF)
 GUICtrlSetState($aTest[1][3] ,$GUI_DISABLE)

WEnd

"not checkable" GUICtrlCreateListViewItem( disable or grey

how ? $GUI_UNCHECKED and $GUI_DISABLE

Link to comment
Share on other sites

  • Moderators

mesale0077,

As far as I know all you can do is remove the checkbox entirely as shown >here. :)

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

#include <GuiListView.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
$Form1_1 = GUICreate("GBC", 1016, 575+20, -1, -1)
$hStatus = _GUICtrlStatusBar_Create($Form1_1 )
_GUICtrlStatusBar_SetText($hStatus, "Status")

$ListView2 = GUICtrlCreateListView(" | ", 16, 108, 986, 454, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlSetBkColor($ListView2, 0xCCCCFF) 

$hListView2 = GUICtrlGetHandle($ListView2)
GUICtrlCreateListViewItem("0|Test 1",$ListView2)

GUICtrlCreateListViewItem("1|test 3",$ListView2)

GUICtrlCreateListViewItem("2|test 4",$ListView2)


GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg

Case $GUI_EVENT_CLOSE

    Exit
EndSwitch
WEnd


Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $hwndFrom, $code, $tInfo
    $tNMHDR = DllStructCreate($tagNMHDR, $LParam)
    $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $code = DllStructGetData($tNMHDR, "Code")
    Local $hWndListView = $ListView2
    If Not IsHWnd($ListView2) Then $hWndListView = GUICtrlGetHandle($ListView2)
    Switch $hwndFrom
        Case $hWndListView
            Switch $code
                Case $NM_CLICK, $NM_DBLCLK, $NM_RCLICK, $NM_RDBLCLK
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $LParam)
                    ;preventing checkboxes from re-apearing (same conditions as above)
                    Switch DllStructGetData($tInfo, "Index")
                        Case 0
                            Return True;intercept normal return message which would cause checkbox to re-apear
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

thank you 1 item disable okay

Edited by mesale0077
Link to comment
Share on other sites

  • Moderators

mesale0077,

Glad I could help. :)

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

2 item grey color  or disabel grey color how?

#include <GuiListView.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
$Form1_1 = GUICreate("GBC", 1016, 575+20, -1, -1)
$hStatus = _GUICtrlStatusBar_Create($Form1_1 )
_GUICtrlStatusBar_SetText($hStatus, "Status")

$ListView2 = GUICtrlCreateListView(" | ", 16, 108, 986, 454, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


$hListView2 = GUICtrlGetHandle($ListView2)
GUICtrlCreateListViewItem("0|Test 1",$ListView2)

GUICtrlCreateListViewItem("1|test 3",$ListView2)

GUICtrlCreateListViewItem("2|test 4",$ListView2)


GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg

Case $GUI_EVENT_CLOSE

    Exit
EndSwitch
WEnd


Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $hwndFrom, $code, $tInfo
    $tNMHDR = DllStructCreate($tagNMHDR, $LParam)
    $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $code = DllStructGetData($tNMHDR, "Code")
    Local $hWndListView = $ListView2
    If Not IsHWnd($ListView2) Then $hWndListView = GUICtrlGetHandle($ListView2)
    Switch $hwndFrom
        Case $hWndListView
            Switch $code
                Case $NM_CLICK, $NM_DBLCLK, $NM_RCLICK, $NM_RDBLCLK
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $LParam)
                    ;preventing checkboxes from re-apearing (same conditions as above)
                    Switch DllStructGetData($tInfo, "Index")
                        Case 1
                        
                            Return True;intercept normal return message which would cause checkbox to re-apear
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc
Edited by mesale0077
Link to comment
Share on other sites

  • Moderators

measle007,

 

Switch DllStructGetData($tInfo, "Index")
    Case 1, 3 ; Put the required indices here <<<<<<<<<<<<<<<<<<<<<<<<<<<
But you are missing the _RemoveCheckbox function - at present you are only preventing the checkbox from being actioned, not removing it altogether. Is that what you want? :huh:

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

t3sNsZe.png

 

checkbox  and item  disable  ,or  grey color like this

but checkbox color disable or grey color how?

#include <GuiListView.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
$Form1_1 = GUICreate("GBC", 1016, 575+20, -1, -1)
$hStatus = _GUICtrlStatusBar_Create($Form1_1 )
_GUICtrlStatusBar_SetText($hStatus, "Status")

$ListView2 = GUICtrlCreateListView(" | ", 16, 108, 986, 454, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


$hListView2 = GUICtrlGetHandle($ListView2)
GUICtrlCreateListViewItem("0|Test 1",$ListView2)

GUICtrlCreateListViewItem("1|test 3",$ListView2)
GUICtrlSetBkColor(-1,0xE0DFE3)
GUICtrlCreateListViewItem("2|test 4",$ListView2)


GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg

Case $GUI_EVENT_CLOSE

    Exit
EndSwitch
WEnd


Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $hwndFrom, $code, $tInfo
    $tNMHDR = DllStructCreate($tagNMHDR, $LParam)
    $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $code = DllStructGetData($tNMHDR, "Code")
    Local $hWndListView = $ListView2
    If Not IsHWnd($ListView2) Then $hWndListView = GUICtrlGetHandle($ListView2)
    Switch $hwndFrom
        Case $hWndListView
            Switch $code
                Case $NM_CLICK, $NM_DBLCLK, $NM_RCLICK, $NM_RDBLCLK
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $LParam)
                    ;preventing checkboxes from re-apearing (same conditions as above)
                    Switch DllStructGetData($tInfo, "Index")
                        Case 1
                        
                            Return True;intercept normal return message which would cause checkbox to re-apear
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc
Edited by mesale0077
Link to comment
Share on other sites

  • Moderators

measle007,

As I said earlier: :(

As far as I know all you can do is remove the checkbox entirely

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

#include <GuiListView.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
$gui3 = 0
$Form1_1 = GUICreate("GBC", 1016, 575+20, -1, -1)
$hStatus = _GUICtrlStatusBar_Create($Form1_1 )
_GUICtrlStatusBar_SetText($hStatus, "Status")

$ListView2 = GUICtrlCreateListView(" | ", 16, 108, 986, 454, -1, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_CHECKBOXES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 220)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 84)
$hListView2 = GUICtrlGetHandle($ListView2)
GUICtrlCreateListViewItem("|Test 1",$ListView2)

GUICtrlCreateListViewItem("|test 3",$ListView2)
GUICtrlSetBkColor(-1,0xE0DFE3)
GUICtrlCreateListViewItem("|test 4",$ListView2)
 GUICtrlCreateCheckbox ("", 22, 153, 20, 19) ;16
 GUICtrlSetBkColor(-1,0xE0DFE3)
    GUICtrlSetState ( -1, $GUI_UNCHECKED + $GUI_DISABLE)

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg

Case $GUI_EVENT_CLOSE

    Exit
EndSwitch
WEnd


Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $hwndFrom, $code, $tInfo
    $tNMHDR = DllStructCreate($tagNMHDR, $LParam)
    $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $code = DllStructGetData($tNMHDR, "Code")
    Local $hWndListView = $ListView2
    If Not IsHWnd($ListView2) Then $hWndListView = GUICtrlGetHandle($ListView2)
    Switch $hwndFrom
        Case $hWndListView
            Switch $code
                Case $NM_CLICK, $NM_DBLCLK, $NM_RCLICK, $NM_RDBLCLK
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $LParam)
                    ;preventing checkboxes from re-apearing (same conditions as above)
                    Switch DllStructGetData($tInfo, "Index")
                        Case 1,3
                        
                            Return True;intercept normal return message which would cause checkbox to re-apear
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

listitemCheckbox pos 

ControlGetPos

GUICtrlCreateCheckbox ("", 22, 153, 20, 19) ;16

GUICtrlSetBkColor(-1,0xE0DFE3)

GUICtrlSetState ( -1, $GUI_UNCHECKED + $GUI_DISABLE)

or

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>

Global $g_idListView, $g_hStatusBar, $g_iIndex = -1, $g_iSubIndex = -1

Example()

Func Example()
    Local $hImage, $hGUI

    ; Create GUI
    $hGUI = GUICreate("ListView SubItem Hit Test", 400, 300)
    $g_idListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    $g_idListView = GUICtrlGetHandle($g_idListView) ; get the handle for use in the notify events
    $g_hStatusBar = _GUICtrlStatusBar_Create($hGUI, -1, "")

    ; Enable extended control styles
    _GUICtrlListView_SetExtendedListViewStyle($g_idListView, $LVS_EX_SUBITEMIMAGES)
    GUISetState(@SW_SHOW)

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_idListView, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_idListView, 0xE0DFE3, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_idListView, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($g_idListView, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($g_idListView, "Column 1", 100)

    _GUICtrlListView_AddColumn($g_idListView, "Column 2", 100)
    _GUICtrlListView_AddColumn($g_idListView, "Column 3", 100)

    ; Add items
    _GUICtrlListView_AddItem($g_idListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($g_idListView, 0, "Row 1: Col 2", 1, 1)
    _GUICtrlListView_AddSubItem($g_idListView, 0, "Row 1: Col 3", 2, 2)
    _GUICtrlListView_AddItem($g_idListView, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($g_idListView, 1, "Row 2: Col 2", 1, 2)
    _GUICtrlListView_AddItem($g_idListView, "Row 3: Col 1", 2)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Func ListView_Click()
    Local $aHit

    $aHit = _GUICtrlListView_SubItemHitTest($g_idListView)
    If ($aHit[0] <> -1) And (($aHit[0] <> $g_iIndex) Or ($aHit[1] <> $g_iSubIndex)) Then
        _GUICtrlStatusBar_SetText($g_hStatusBar, @TAB & StringFormat("HitTest Item: %d, SubItem: %d", $aHit[0], $aHit[1]))
        $g_iIndex = $aHit[0]
        $g_iSubIndex = $aHit[1]
    EndIf
EndFunc   ;==>ListView_Click

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $g_idListView
    If Not IsHWnd($g_idListView) Then $hWndListView = GUICtrlGetHandle($g_idListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    _DebugPrint("$LVN_COLUMNCLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
                    ; No return value
                Case $LVN_KEYDOWN ; A key has been pressed
                    $tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam)
                    _DebugPrint("$LVN_KEYDOWN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->VKey:" & @TAB & DllStructGetData($tInfo, "VKey") & @CRLF & _
                            "-->Flags:" & @TAB & DllStructGetData($tInfo, "Flags"))
                    ; No return value
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ListView_Click()
                    ; No return value
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ; No return value
                Case $NM_KILLFOCUS ; The control has lost the input focus
                    _DebugPrint("$NM_KILLFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_RCLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ;Return 1 ; not to allow the default processing
                    Return 0 ; allow the default processing
                Case $NM_RDBLCLK ; Sent by a list-view control when the user double-clicks an item with the right mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _DebugPrint("$NM_RDBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode & @CRLF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
                    ; No return value
                Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key
                    _DebugPrint("$NM_RETURN" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
                Case $NM_SETFOCUS ; The control has received the input focus
                    _DebugPrint("$NM_SETFOCUS" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                            "-->Code:" & @TAB & $iCode)
                    ; No return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_Text , $sLine = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @CRLF & _
            "+======================================================" & @CRLF & _
            "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text  & @CRLF & _
            "+======================================================" & @CRLF)
EndFunc

 only 2.item grey color

# @mesale0077 tarafından yapıldı.

#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <GuiListView.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
$Form1_1 = GUICreate("GBC", 1016, 575+20, -1, -1)
$hStatus = _GUICtrlStatusBar_Create($Form1_1 )
_GUICtrlStatusBar_SetText($hStatus, "Status")

$ListView2 = GUICtrlCreateListView(" | ", 16, 108, 986, 454, -1, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_CHECKBOXES))
$hListView2 = GUICtrlGetHandle($ListView2)
GUICtrlCreateListViewItem("0|Test 1",$ListView2)

GUICtrlCreateListViewItem("|test 3",$ListView2)
GUICtrlSetBkColor(-1,0xE0DFE3)
GUICtrlCreateListViewItem("2|test 4",$ListView2)

   $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($ListView2), 0xE0DFE3, 16, 16))
    _GUICtrlListView_SetImageList($ListView2, $hImage, 2)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg

Case $GUI_EVENT_CLOSE

    Exit
EndSwitch
WEnd


Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $hwndFrom, $code, $tInfo
    $tNMHDR = DllStructCreate($tagNMHDR, $LParam)
    $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $code = DllStructGetData($tNMHDR, "Code")
    Local $hWndListView = $ListView2
    If Not IsHWnd($ListView2) Then $hWndListView = GUICtrlGetHandle($ListView2)
    Switch $hwndFrom
        Case $hWndListView
            Switch $code
                Case $NM_CLICK, $NM_DBLCLK, $NM_RCLICK, $NM_RDBLCLK
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $LParam)
                    ;preventing checkboxes from re-apearing (same conditions as above)
                    Switch DllStructGetData($tInfo, "Index")
                        Case 1,3
                        
                            Return True;intercept normal return message which would cause checkbox to re-apear
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc
Edited by mesale0077
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...