Jump to content
Sign in to follow this  

Please, How to change the color of an Item GuictrlcreateListview ?

Recommended Posts



I adapted a script to change color items but does not work can someone help.


my script is as follows:


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <FontConstants.au3>
#include <WinAPI.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 272, 264, 75, 25)
$ListView1 = GUICtrlCreateListView("nº |     col1  |     col2 |    col3 "  , 72, 88, 474, 150, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 30)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 150)
_GUICtrlListView_GetColumn($ListView1, 0)
_GUICtrlListView_JustifyColumn($ListView1, 0, 2)
_GUICtrlListView_GetColumn($ListView1, 1)
_GUICtrlListView_JustifyColumn($ListView1, 1, 2)
_GUICtrlListView_GetColumn($ListView1, 2)
_GUICtrlListView_JustifyColumn($ListView1, 1, 0)
_GUICtrlListView_GetColumn($ListView1, 3)
_GUICtrlListView_JustifyColumn($ListView1, 1, 0)
#EndRegion ### END Koda GUI section ###
Global $Font1 = _WinAPI_CreateFont(14, 6, 0, 0, $FW_BOLD),$iItem
Global $Font2 = _WinAPI_CreateFont(14, 6, 0, 0, $FW_BOLD, True)
For $a = 1 to 200
   IF Mod($a, 2) = 0 Then
   $Var = "stock "
   $Var1 = "not out"
   $Var2 = "Color Blue"
   $Var = "no stock"
   $Var1 = "exhausted"
   $Var2 = "Color Red"
   GUICtrlCreateListViewItem($a &"|"   &$Var&"|"&$Var1&"|"&$Var2, $ListView1)
While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
   Case $Button1
   For $iItem = 0 to _GUICtrlListView_GetItemCount($ListView1)
      IF _GUICtrlListView_GetItemText($ListView1,$iItem,1) = "no stock" Then
      GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $ListView1
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                    Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
                    If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
                    Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
                    Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
                    Local $iColor, $hDC
                    Switch $iItem
                        Case 0
                            $hDC = DllStructGetData($tCustDraw, "hdc")
         $iColor = 0x5555DD
         _WinAPI_SelectObject($hDC, $Font1)
         DllStructSetData($tCustDraw, "clrText", $iColor)
         Return $CDRF_NEWFONT
EndFunc   ;==>WM_NOTIFY
Edited by Melba23
Added code tags

Share this post

Link to post
Share on other sites


Thanks also serves me, but I want also to change the color of text in a subitem.

Share this post

Link to post
Share on other sites

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.

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.