Jump to content

Setting child color to Treeview items


DickG
 Share

Recommended Posts

I can set the color to the Parent item, but not to the Child item.

So I tried using the Help file example to set the color to parent and child items.

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hItem, $hImage, $iImage, $idTreeView
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

    GUICreate("TreeView Add Child", 400, 300)

    $idTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
    GUISetState(@SW_SHOW)

    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 110)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 131)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 165)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 168)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 137)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 146)
    _GUICtrlTreeView_SetNormalImageList($idTreeView, $hImage)

    _GUICtrlTreeView_BeginUpdate($idTreeView)
    For $x = 1 To Random(2, 10, 1)
        $iImage = Random(0, 5, 1)
        $hItem = _GUICtrlTreeView_Add($idTreeView, 0, StringFormat("[%02d] New Item", $x), $iImage, $iImage)
        GUICtrlSetBkColor($hItem, "0xFCECB4")
        For $y = 1 To Random(2, 10, 1)
            $iImage = Random(0, 5, 1)
            _GUICtrlTreeView_AddChild($idTreeView, $hItem, StringFormat("[%02d] New Child", $y), $iImage, $iImage)
            GUICtrlSetBkColor($hItem, "0xFE304F")
        Next
    Next
    _GUICtrlTreeView_EndUpdate($idTreeView)

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

But it doesn't change any color at all.

Any idea why?

Edited by DickG
Link to comment
Share on other sites

GUICtrlSetBkColor needs a CtrlID (return from native GUICtrl functions), not a handle (return from _GUICtrl UDFs).  This complicates things a little (have to apply Image List Index afterwards), but is doable.

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hItem, $hImage, $iImage, $idTreeView
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

    GUICreate("TreeView Add Child", 400, 300)

    $idTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
    GUISetState(@SW_SHOW)

    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 110)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 131)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 165)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 168)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 137)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 146)
    _GUICtrlTreeView_SetNormalImageList($idTreeView, $hImage)

    _GUICtrlTreeView_BeginUpdate($idTreeView)
    For $x = 1 To Random(2, 10, 1)
        $iImage = Random(0, 5, 1)
        ;$hItem = _GUICtrlTreeView_Add($idTreeView, 0, StringFormat("[%02d] New Item", $x), $iImage, $iImage)
        $hItem = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x), $idTreeView)
        GUICtrlSetBkColor(-1, "0xFCECB4")
        _GUICtrlTreeView_SetImageIndex($idTreeView, $hItem, $iImage)
        For $y = 1 To Random(2, 10, 1)
            $iImage = Random(0, 5, 1)
            ;_GUICtrlTreeView_AddChild($idTreeView, $hItem, StringFormat("[%02d] New Child", $y), $iImage, $iImage)
            $hChild = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Child", $y), $hItem)
            GUICtrlSetBkColor(-1, "0xFE304F")
            _GUICtrlTreeView_SetImageIndex($idTreeView, $hChild, $iImage)
        Next
    Next
    _GUICtrlTreeView_EndUpdate($idTreeView)

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

 

Edited by spudw2k
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...