Jump to content
Sign in to follow this  
dragonlord

Listview Subitem tracking + Gridlines+Checkbox

Recommended Posts

dragonlord

I'm hottracking a listview using the below code:

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    If Not IsHWnd($hTab) Then $hWndTab = GUICtrlGetHandle($Tab1)

   Switch $hWndFrom
        Case $hListView2 
            Switch $iCode
                Case $LVN_HOTTRACK ; Sent by a list-view control when the user moves the mouse over an item
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    $iItem = DllStructGetData($tInfo, "Item")
                    $iSubItem = DllStructGetData($tInfo, "SubItem")
                    _GUICtrlStatusBar_SetText($hStatus, $iItem  &","&$iSubItem )

                Case $NM_CUSTOMDRAW
                    If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG
                     Local $tCustDraw = DllStructCreate('hwnd hwndFrom;int idFrom;int code;' & _
                                        'dword DrawStage;hwnd hdc;long rect[4];dword ItemSpec;int ItemState;dword Itemlparam;' & _
                                        'dword clrText;dword clrTextBk;int SubItem;' & _
                                        'dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartID;int StateID;long rectText[4];int Align', _ ;winxp or later
                                        $lParam), $iDrawStage, $iItem, $iSubitem, $hDC, $iColor1, $iColor2, $iColor3
                    $iDrawStage = DllStructGetData($tCustDraw, 'DrawStage')
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW ;request custom drawing of items
                    If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW ;request drawing each cell separately
                    If Not BitAND($iDrawStage, $CDDS_SUBITEM) Then Return $CDRF_DODEFAULT
                    $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                    $iSubitem = DllStructGetData($tCustDraw, 'SubItem')
;~                  ConsoleWrite(@CRLF & "$iItem = " & $iItem & ", $iSubitem ="&$iSubitem &", text="& _GUICtrlListView_GetItemText($hListView2, $iItem ,$iSubitem))
                            $iColor1 = RGB2BGR(0xFBFFD8)
                            $iColor2 = RGB2BGR(-1)
                            $iColor3 = RGB2BGR(0xFF0000)
                            $ColorDisabletext=RGB2BGR(0xdcdcdc)
                            if StringInStr(_GUICtrlListView_GetItemText($hListView2, $iItem ,$iSubitem),"Fail") Then
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                DllStructSetData($tCustDraw, 'clrText', RGB2BGR(0xcd5c5c))
                             EndIf
                           if StringInStr(_GUICtrlListView_GetItemText($hListView2, $iItem ,$iSubitem),"Pass") Then
                                DllStructSetData($tCustDraw, 'clrTextBk', $iColor2)
                                DllStructSetData($tCustDraw, 'clrText', RGB2BGR(0x008000))
                             EndIf
                             if StringInStr(_GUICtrlListView_GetItemText($hListView2, $iItem ,$iSubitem),"In Progress") Then
                                DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR(0x000000))
                                DllStructSetData($tCustDraw, 'clrText', RGB2BGR(0xffd700))
                             EndIf

                    Return $CDRF_NEWFONT
            EndSwitch
 
    EndSwitch
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

This works fine with a regular ListView like this :

$ListView2 = GUICtrlCreateListView(" | ", 16, 108, 986, 454)

But, I need gridlines and checkboxes too, which doesnt work currently:

$ListView2 = GUICtrlCreateListView(" | ", 16, 108, 986, 454, BitOR($LVS_REPORT,$LVS_ALIGNLEFT), BitOR($LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES))

Any workarounds to this?

Share this post


Link to post
Share on other sites
Melba23

dragonlord,

If you give us some code which we can run then perhaps we might be able to help - but I for one an certainly not writing all the additional code to test the function you posted. ;)

M23

Edited by Melba23
Typo

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 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

 

Share this post


Link to post
Share on other sites
dragonlord

 My bad, here some sample code :

#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")

;~ Hottracking works
$ListView2 = GUICtrlCreateListView(" | ", 16, 108, 986, 454)

;~ Hottracking doesnt work
;~ $ListView2 = GUICtrlCreateListView(" | ", 16, 108, 986, 454, BitOR($LVS_REPORT,$LVS_ALIGNLEFT), BitOR($LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES))

$hListView2 = GUICtrlGetHandle($ListView2)
GUICtrlCreateListViewItem("0|Test 1",$ListView2)
_GUICtrlListView_SetItemChecked($ListView2, -1, True)
GUICtrlCreateListViewItem("1|test 3",$ListView2)
_GUICtrlListView_SetItemChecked($ListView2, -1, True)
GUICtrlCreateListViewItem("2|test 4",$ListView2)
_GUICtrlListView_SetItemChecked($ListView2, -1, True)
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 1, 50)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
$nMsg = GUIGetMsg()
Switch $nMsg

Case $GUI_EVENT_CLOSE
    
    Exit
EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    
   Switch $hWndFrom
        Case $hListView2 
            Switch $iCode
                Case $LVN_HOTTRACK ; Sent by a list-view control when the user moves the mouse over an item
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    $iItem = DllStructGetData($tInfo, "Item")
                    $iSubItem = DllStructGetData($tInfo, "SubItem")
                    _GUICtrlStatusBar_SetText($hStatus, $iItem  &","&$iSubItem )

                Case $NM_CUSTOMDRAW
                    If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG
                     Local $tCustDraw = DllStructCreate('hwnd hwndFrom;int idFrom;int code;' & _
                                        'dword DrawStage;hwnd hdc;long rect[4];dword ItemSpec;int ItemState;dword Itemlparam;' & _
                                        'dword clrText;dword clrTextBk;int SubItem;' & _
                                        'dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartID;int StateID;long rectText[4];int Align', _ ;winxp or later
                                        $lParam), $iDrawStage, $iItem, $iSubitem, $hDC, $iColor1, $iColor2, $iColor3
                    $iDrawStage = DllStructGetData($tCustDraw, 'DrawStage')
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW ;request custom drawing of items
                    If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW ;request drawing each cell separately
                    If Not BitAND($iDrawStage, $CDDS_SUBITEM) Then Return $CDRF_DODEFAULT
                    $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                    $iSubitem = DllStructGetData($tCustDraw, 'SubItem')
                    Return $CDRF_NEWFONT
            EndSwitch
EndSwitch

Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edited by dragonlord

Share this post


Link to post
Share on other sites
Melba23

dragonlord,

Looking at it - I think I may have a workaround.  Stay tuned. :)

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 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

 

Share this post


Link to post
Share on other sites
Melba23

dragonlord,

Better still, I have a solution! :party:

Just add the $LVS_EX_FULLROWSELECT style to the ListView and the status bar updates correctly:

#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")

;~ Hottracking works
;$ListView2 = GUICtrlCreateListView(" | ", 16, 108, 986, 454)

;~ Hottracking doesnt work
$ListView2 = GUICtrlCreateListView(" | ", 16, 108, 986, 454, BitOR($LVS_REPORT, $LVS_ALIGNLEFT), BitOR($LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlSetBkColor($ListView2, 0xCCCCFF) ; I need this to see the gridlines

$hListView2 = GUICtrlGetHandle($ListView2)
GUICtrlCreateListViewItem("0|Test 1",$ListView2)
_GUICtrlListView_SetItemChecked($ListView2, -1, True)
GUICtrlCreateListViewItem("1|test 3",$ListView2)
_GUICtrlListView_SetItemChecked($ListView2, -1, True)
GUICtrlCreateListViewItem("2|test 4",$ListView2)
_GUICtrlListView_SetItemChecked($ListView2, -1, True)
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 1, 50)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
$nMsg = GUIGetMsg()
Switch $nMsg

Case $GUI_EVENT_CLOSE

    Exit
EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")


   Switch $hWndFrom
        Case $hListView2
            Switch $iCode
                Case $LVN_HOTTRACK ; Sent by a list-view control when the user moves the mouse over an item
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    $iItem = DllStructGetData($tInfo, "Item")
                    $iSubItem = DllStructGetData($tInfo, "SubItem")
                    _GUICtrlStatusBar_SetText($hStatus, $iItem  &","&$iSubItem )

                Case $NM_CUSTOMDRAW
                    If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG
                     Local $tCustDraw = DllStructCreate('hwnd hwndFrom;int idFrom;int code;' & _
                                        'dword DrawStage;hwnd hdc;long rect[4];dword ItemSpec;int ItemState;dword Itemlparam;' & _
                                        'dword clrText;dword clrTextBk;int SubItem;' & _
                                        'dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartID;int StateID;long rectText[4];int Align', _ ;winxp or later
                                        $lParam), $iDrawStage, $iItem, $iSubitem, $hDC, $iColor1, $iColor2, $iColor3
                    $iDrawStage = DllStructGetData($tCustDraw, 'DrawStage')
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW ;request custom drawing of items
                    If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW ;request drawing each cell separately
                    If Not BitAND($iDrawStage, $CDDS_SUBITEM) Then Return $CDRF_DODEFAULT
                    $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                    $iSubitem = DllStructGetData($tCustDraw, 'SubItem')
                    Return $CDRF_NEWFONT
            EndSwitch
EndSwitch

Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

I hope it works for you too. :)

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 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

 

Share this post


Link to post
Share on other sites
dragonlord

dragonlord,

Better still, I have a solution! :party:

Just add the $LVS_EX_FULLROWSELECT style to the ListView and the status bar updates correctly:

#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")

;~ Hottracking works
;$ListView2 = GUICtrlCreateListView(" | ", 16, 108, 986, 454)

;~ Hottracking doesnt work
$ListView2 = GUICtrlCreateListView(" | ", 16, 108, 986, 454, BitOR($LVS_REPORT, $LVS_ALIGNLEFT), BitOR($LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUICtrlSetBkColor($ListView2, 0xCCCCFF) ; I need this to see the gridlines

$hListView2 = GUICtrlGetHandle($ListView2)
GUICtrlCreateListViewItem("0|Test 1",$ListView2)
_GUICtrlListView_SetItemChecked($ListView2, -1, True)
GUICtrlCreateListViewItem("1|test 3",$ListView2)
_GUICtrlListView_SetItemChecked($ListView2, -1, True)
GUICtrlCreateListViewItem("2|test 4",$ListView2)
_GUICtrlListView_SetItemChecked($ListView2, -1, True)
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 1, 50)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
$nMsg = GUIGetMsg()
Switch $nMsg

Case $GUI_EVENT_CLOSE

    Exit
EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")


   Switch $hWndFrom
        Case $hListView2
            Switch $iCode
                Case $LVN_HOTTRACK ; Sent by a list-view control when the user moves the mouse over an item
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    $iItem = DllStructGetData($tInfo, "Item")
                    $iSubItem = DllStructGetData($tInfo, "SubItem")
                    _GUICtrlStatusBar_SetText($hStatus, $iItem  &","&$iSubItem )

                Case $NM_CUSTOMDRAW
                    If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG
                     Local $tCustDraw = DllStructCreate('hwnd hwndFrom;int idFrom;int code;' & _
                                        'dword DrawStage;hwnd hdc;long rect[4];dword ItemSpec;int ItemState;dword Itemlparam;' & _
                                        'dword clrText;dword clrTextBk;int SubItem;' & _
                                        'dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartID;int StateID;long rectText[4];int Align', _ ;winxp or later
                                        $lParam), $iDrawStage, $iItem, $iSubitem, $hDC, $iColor1, $iColor2, $iColor3
                    $iDrawStage = DllStructGetData($tCustDraw, 'DrawStage')
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW ;request custom drawing of items
                    If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW ;request drawing each cell separately
                    If Not BitAND($iDrawStage, $CDDS_SUBITEM) Then Return $CDRF_DODEFAULT
                    $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                    $iSubitem = DllStructGetData($tCustDraw, 'SubItem')
                    Return $CDRF_NEWFONT
            EndSwitch
EndSwitch

Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

I hope it works for you too. :)

M23

Awesome.

Works great.

You the man !

Share this post


Link to post
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
Sign in to follow this  

×