Jump to content
nyke0

Listview - font coloring a single item?

Recommended Posts

nyke0

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 350, 250, -1, -1)
$ListView1 = GUICtrlCreateListView("Header|Header|Header", 0, 0, 350, 250)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

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

    EndSwitch
WEnd

Can I color the single font color (not the background) to green or other color than all the other ones?

Share this post


Link to post
Share on other sites
Melba23

nyke0,

You can make the whole line green by doing this:

GuiCtrlCreateListViewItem('Black|GREEN?|Black',$ListView1)
GUICtrlSetColor(-1, 0x00FF00)
If you want to colour just the single sub-item then you are into owner-drawn ListViews - search the forum, there are some good examples out there. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
mikell

Very common question 

#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

                     If $iItem = 1 and $iSubItem = 1 Then $iColor = RGB2BGR(0x00cc00)
                     DllStructSetData($tCustDraw, "clrText", $iColor)
                     Return $CDRF_NEWFONT
             EndSwitch
     EndSwitch
    Return $GUI_RUNDEFMSG
 EndFunc   ;==>WM_NOTIFY

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

Many possible additional features mentioned everywhere on the forum  :)

Share this post


Link to post
Share on other sites
Adele

Can we change color of the specified item without use the value returning from GuiCtrlCreateListViewItem()?

Share this post


Link to post
Share on other sites
kylomas

If you mean the value populating the listview cell, then yes...

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

                     If $iItem = 1 and $iSubItem = 1 Then $iColor = RGB2BGR(0xcc0000)
                     DllStructSetData($tCustDraw, "clrText", $iColor)
                     Return $CDRF_NEWFONT
             EndSwitch
     EndSwitch
    Return $GUI_RUNDEFMSG
 EndFunc   ;==>WM_NOTIFY

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

kylomas

edit: Stick to one thread per question please.  You asked the same question >here.  If you are not getting a timely response (at least 24 hours) then open your own thread.

Edited by kylomas
  • Like 2

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Melba23

Adele,

If you want to colour the whole line rather then just the subitem it is a bit simpler: ;)

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

$hGUI = GUICreate("Test", 500, 500)

$cListView = GUICtrlCreateListView("Header|Header|Header", 0, 0, 350, 250)

GUICtrlCreateListViewItem('00|01|02', $cListView)
GUICtrlCreateListViewItem('10|11|12', $cListView)
GUICtrlCreateListViewItem('20|21|22', $cListView)

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

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


Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $tNMLISTVIEW, $iItem, $iCode, $cID
    $tNMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam)
    $iCode = DllStructGetData($tNMLISTVIEW, "Code")

    If $iCode = $NM_CLICK Then
        $iItem = DllStructGetData($tNMLISTVIEW, "Item")
        $cID = _GUICtrlListView_GetItemParam($cListView, $iItem) ; Autoit stores the ControlID in the item paramter
        GUICtrlSetColor($cID, 0xFF0000)
    EndIf

EndFunc   ;==>_WM_NOTIFY
M23
  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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
Adele

kylomas, Melba23 they worked. Thank you.

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

×