Jump to content
Sign in to follow this  
nyke0

Color a single item in a Listview?

Recommended Posts

I don't mean a full row or column, a Item only. I found some splutions, but it seems they don't work anymore.

Share this post


Link to post
Share on other sites

Helping with Mikell's code >here :

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

$Form1 = GUICreate("Form1", 350, 250, -1, -1)
$ListView1 = GUICtrlCreateListView("Header|Header|Header", 0, 0, 350, 250)

GuiCtrlCreateListViewItem('Black|Black|Black',$ListView1)
GuiCtrlCreateListViewItem('Black|GREEN?|Black',$ListView1)
GuiCtrlCreateListViewItem('Black|Black|Black',$ListView1)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
     Local $tNMHDR, $hWndFrom, $iCode
     $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
     $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
     $iCode = DllStructGetData($tNMHDR, "Code")
     $hListView = GuiCtrlGetHandle($ListView1)

    Switch $hWndFrom
         Case $hListView
             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, $iColor2 = RGB2BGR(0xFFFFFF)

                     If $iItem = 1 and $iSubItem = 1 Then
                        $iColor = RGB2BGR(0x00cc00)
                        $iColor2 = RGB2BGR(0xcc00cc)
                    EndIf
                     DllStructSetData($tCustDraw, "clrText", $iColor)    ; text color
                     DllStructSetData($tCustDraw, "clrTextBk", $iColor2) ; background color
                     Return $CDRF_NEWFONT
             EndSwitch
     EndSwitch
    Return $GUI_RUNDEFMSG
 EndFunc   ;==>WM_NOTIFY

Func RGB2BGR($iColor)
     Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc   ;==>RGB2BGR()

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  

×
×
  • Create New...