Jump to content

HOW TO SET BACKGROUND LISTVIEW COLOR?


Recommended Posts

hi guys, i have a problem, i'm triying to set background color of a list view like that:

 

$hListView = _GUICtrlListView_Create($Form2, "", 10, 90, $x-20, 200)
$ID = _GUICtrlTreeView_GetItemParam($hListView)
GUISetBkColor ($COLOR_RED,$ID)

 

buts is not working, i try by these way bellow and its worked:

$hListView = GUICtrlCreateListView("",  10, 90, $x-20, 200)
GUICtrlSetBkColor(-1, $COLOR_RED)

but at these way the function bellow doenst works:

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hListView And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hListView)
        If $aLV_Click_Info[0] <> -1 Then $fDblClk = True
    EndIf
    Return $GUI_RUNDEFMSG

EndFunc

 

can anyone help me? (sorry about my english)

Link to comment
Share on other sites

  • Moderators

Melque_Lima,

Welcome to the AutoIt forums.

But please stop PMing and double posting.  Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare.  You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online - like now!

You need to understand the difference between the native AutoIt commands (GUICtrlCreate...) and the UDF commands (_GUICtrl..._Create) - the former return a ControlID which is used internally by AutoIt to address the control, where as the latter return a Windows handle which is used by Windows to identify almost everything in the system.

If you look at the Help file for GUICtrlSetBkColor (not GUISetBkColor as you were using - that is only for GUIs, not controls) you will see that you need to use a ControlID to identify the control and so the function only works on ListViews created with the native commands. If you want to colour a UDF-created ListView, you need to use _GUICtrlListView_SetBkColor.

Has that made any sense? Please tell me if not and we can take things a little slower.

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

 

Link to comment
Share on other sites

Can you post a reproducer script (either snippet that produces issue or complete script)?

I think you got the  _GUICtrlListView_SetBkColor  func figured out (...yes?), but not sure what you need help with now.

Link to comment
Share on other sites

spudw2k,

the full code bellow

 

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
#include <GuiButton.au3>
#include <GuiListView.au3>
#include <FontConstants.au3>
#include <Misc.au3>
#include <GuiTreeView.au3>

Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 0)
HotKeySet("+!d",'Modo_ADM')


Global $fDblClk = False
Global $aLV_Click_Info, $hTmp_Edit = 0
$dll = DllOpen("user32.dll")

#region configuração de form
$x = 500
$y = 500
$w =(@DesktopWidth/2)-($x/2)
$h =(@DesktopHeight/2)-($y/2)

Global $Form2 = GUICreate("Tabela", $x, $y, $w, $h,BitOR($WS_POPUP, $DS_SETFOREGROUND))
GUISetBkColor(0x505050)
GUICtrlSetDefColor(0xc1c1c1)
#EndRegion


#Region botoes de comando da janela
    $x_label = GUICtrlCreateLabel("X", 470, 10, 20, 20, BitOr($SS_NOTIFY, $SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN))
    GUISetOnEvent($GUI_EVENT_CLOSE, "close")
    GUICtrlSetOnEvent(-1, "close")
    GUICtrlSetBkColor(-1, 0x414141)
    $ctrlpos = ControlGetPos($Form2, "", $x_label)
    GUICtrlCreatePic(@ScriptDir & '\' & "gradient.bmp", $ctrlpos[0],$ctrlpos[1], $ctrlpos[2],$ctrlpos[3])
#EndRegion

#Region Outros
    GUICtrlCreateLabel("-- Controle --", 10, 40, 480, 30, BitOr($SS_NOTIFY, $SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN))
    GUICtrlSetBkColor(-1, 0x991010)
    GUICtrlSetFont (-1,15,$FW_HEAVY)

#EndRegion

#Region Configurações de lista
$hListView = _GUICtrlListView_Create($Form2, "", 10, 90, $x-20, 200)
;MsgBox(0,"",$hListView)
_GUICtrlListView_SetBkColor($hListView,0x414141)
;$hListView = GUICtrlCreateListView("",  10, 90, $x-20, 200);,$LVS_NOCOLUMNHEADER )

;MsgBox(0,"",_WinAPI_GetHandleInformation($hListView))
;_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR(0, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_INFOTIP))
;GUICtrlSetBkColor(10000, 0x414141)
;$r = _GUICtrlTreeView_GetItemParam($hListView)
;GUISetBkColor ($COLOR_RED,$r)
;GUICtrlSetBkColor($r, 0x414141)


_GUICtrlListView_AddColumn($hListView, "Nome",240)
_GUICtrlListView_AddColumn($hListView, "Caixa 2",78)
_GUICtrlListView_AddColumn($hListView, "Mensal",78)
_GUICtrlListView_AddColumn($hListView, "Data",78)

_GUICtrlListView_AddItem($hListView, "") ; Adciona uma nova linha
_GUICtrlListView_AddSubItem($hListView,0,"TEST",0)
_GUICtrlListView_AddSubItem($hListView,0,"5,235",1)
_GUICtrlListView_AddSubItem($hListView,0,"1.0215.586",2)
_GUICtrlListView_AddSubItem($hListView,0,"23/12/1991",3)


#EndRegion


#Region variaveis
    Global $fDblClk = False
    Global $hotkey = false
#EndRegion

;$label3 = GUICtrlCreateLabel("Don't do that", 10,50, -1,-1, BitOr($SS_CENTER, $SS_CENTERIMAGE))
;GUICtrlSetBkColor(-1, 0x991010)

;GUICtrlCreateLabel("Browse", 10, 10, 60, 25, BitOr($SS_NOTIFY, $SS_CENTER, $SS_CENTERIMAGE))
;GUICtrlSetOnEvent(-1, "Hi")
;GUICtrlSetBkColor(-1, 0x414141)



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

While 1

 ; If a temporary edit exists
    If $hTmp_Edit <> 0 Then
        ; If ENTER pressed
        If _IsPressed("0D", $dll) Then
            ; Set label to edit content
            $sText = GUICtrlRead($hTmp_Edit)
            _GUICtrlListView_SetItemText($hListView, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1])
            ; Delete temporary edit
            GUICtrlDelete($hTmp_Edit)
            $hTmp_Edit = 0
        EndIf
        ; If ESC pressed
        If _IsPressed("1B", $dll) Then
            ; Delete temporary edit
            GUICtrlDelete($hTmp_Edit)
            $hTmp_Edit = 0
        EndIf
    EndIf

    ; If an item was double clicked
    If $fDblClk Then
        $fDblClk = False
        ; Delete any existing temporary edits
        GUICtrlDelete($hTmp_Edit)
        ;$hTmp_Edit = 0
        ; Read current text of clicked label
        $sTmp_Text = _GUICtrlListView_GetItemText($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
        ; Get label position
        Switch $aLV_Click_Info[1]
            Case 0 ; On Item
                $aLV_Rect_Info = _GUICtrlListView_GetItemRect($hListView, $aLV_Click_Info[0], 2)
            Case Else ; On SubItem
                $aLV_Rect_Info = _GUICtrlListView_GetSubItemRect($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
        EndSwitch
        ; Create temporary edit
        $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aLV_Rect_Info[0] + 10, $aLV_Rect_Info[1] + 90, $aLV_Rect_Info[2] - $aLV_Rect_Info[0], $aLV_Rect_Info[3] - $aLV_Rect_Info[1], 0)
        GUICtrlSetState($hTmp_Edit, $GUI_FOCUS)

    EndIf

WEnd


func close()
    exit
EndFunc

Func Modo_ADM()

if not $hotkey Then
    $hotkey = true
    Global $pass=InputBox("Security", "Digite a senha para modo ADM","" , "*M")
    if $pass == "senha" Then
        MsgBox(0,"","Acesso ADM autorizado!!")
    Else
        MsgBox(0,"","Senha incorreta")
    EndIf
    $hotkey = false
EndIf

EndFunc


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hListView And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hListView)
        If $aLV_Click_Info[0] <> -1 Then $fDblClk = True
    EndIf
    Return $GUI_RUNDEFMSG

EndFunc

 

lines between 48 and 74

the lines are with white background, how can i fix it?

 

thanks for your support

Link to comment
Share on other sites

1 minute ago, Melque_Lima said:

spudw2k,

the full code bellow

 

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiImageList.au3>
#include <GuiButton.au3>
#include <GuiListView.au3>
#include <FontConstants.au3>
#include <Misc.au3>
#include <GuiTreeView.au3>

Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 0)
HotKeySet("+!d",'Modo_ADM')


Global $fDblClk = False
Global $aLV_Click_Info, $hTmp_Edit = 0
$dll = DllOpen("user32.dll")

#region configuração de form
$x = 500
$y = 500
$w =(@DesktopWidth/2)-($x/2)
$h =(@DesktopHeight/2)-($y/2)

Global $Form2 = GUICreate("Tabela", $x, $y, $w, $h,BitOR($WS_POPUP, $DS_SETFOREGROUND))
GUISetBkColor(0x505050)
GUICtrlSetDefColor(0xc1c1c1)
#EndRegion


#Region botoes de comando da janela
    $x_label = GUICtrlCreateLabel("X", 470, 10, 20, 20, BitOr($SS_NOTIFY, $SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN))
    GUISetOnEvent($GUI_EVENT_CLOSE, "close")
    GUICtrlSetOnEvent(-1, "close")
    GUICtrlSetBkColor(-1, 0x414141)
    $ctrlpos = ControlGetPos($Form2, "", $x_label)
    GUICtrlCreatePic(@ScriptDir & '\' & "gradient.bmp", $ctrlpos[0],$ctrlpos[1], $ctrlpos[2],$ctrlpos[3])
#EndRegion

#Region Outros
    GUICtrlCreateLabel("-- Controle --", 10, 40, 480, 30, BitOr($SS_NOTIFY, $SS_CENTER, $SS_CENTERIMAGE, $SS_SUNKEN))
    GUICtrlSetBkColor(-1, 0x991010)
    GUICtrlSetFont (-1,15,$FW_HEAVY)

#EndRegion

#Region Configurações de lista
$hListView = _GUICtrlListView_Create($Form2, "", 10, 90, $x-20, 200)
;MsgBox(0,"",$hListView)
_GUICtrlListView_SetBkColor($hListView,0x414141)
;$hListView = GUICtrlCreateListView("",  10, 90, $x-20, 200);,$LVS_NOCOLUMNHEADER )

;MsgBox(0,"",_WinAPI_GetHandleInformation($hListView))
;_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR(0, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_INFOTIP))
;GUICtrlSetBkColor(10000, 0x414141)
;$r = _GUICtrlTreeView_GetItemParam($hListView)
;GUISetBkColor ($COLOR_RED,$r)
;GUICtrlSetBkColor($r, 0x414141)


_GUICtrlListView_AddColumn($hListView, "Nome",240)
_GUICtrlListView_AddColumn($hListView, "Caixa 2",78)
_GUICtrlListView_AddColumn($hListView, "Mensal",78)
_GUICtrlListView_AddColumn($hListView, "Data",78)

_GUICtrlListView_AddItem($hListView, "") ; Adciona uma nova linha
_GUICtrlListView_AddSubItem($hListView,0,"TEST",0)
_GUICtrlListView_AddSubItem($hListView,0,"5,235",1)
_GUICtrlListView_AddSubItem($hListView,0,"1.0215.586",2)
_GUICtrlListView_AddSubItem($hListView,0,"23/12/1991",3)


#EndRegion


#Region variaveis
    Global $fDblClk = False
    Global $hotkey = false
#EndRegion

;$label3 = GUICtrlCreateLabel("Don't do that", 10,50, -1,-1, BitOr($SS_CENTER, $SS_CENTERIMAGE))
;GUICtrlSetBkColor(-1, 0x991010)

;GUICtrlCreateLabel("Browse", 10, 10, 60, 25, BitOr($SS_NOTIFY, $SS_CENTER, $SS_CENTERIMAGE))
;GUICtrlSetOnEvent(-1, "Hi")
;GUICtrlSetBkColor(-1, 0x414141)



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

While 1

 ; If a temporary edit exists
    If $hTmp_Edit <> 0 Then
        ; If ENTER pressed
        If _IsPressed("0D", $dll) Then
            ; Set label to edit content
            $sText = GUICtrlRead($hTmp_Edit)
            _GUICtrlListView_SetItemText($hListView, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1])
            ; Delete temporary edit
            GUICtrlDelete($hTmp_Edit)
            $hTmp_Edit = 0
        EndIf
        ; If ESC pressed
        If _IsPressed("1B", $dll) Then
            ; Delete temporary edit
            GUICtrlDelete($hTmp_Edit)
            $hTmp_Edit = 0
        EndIf
    EndIf

    ; If an item was double clicked
    If $fDblClk Then
        $fDblClk = False
        ; Delete any existing temporary edits
        GUICtrlDelete($hTmp_Edit)
        ;$hTmp_Edit = 0
        ; Read current text of clicked label
        $sTmp_Text = _GUICtrlListView_GetItemText($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
        ; Get label position
        Switch $aLV_Click_Info[1]
            Case 0 ; On Item
                $aLV_Rect_Info = _GUICtrlListView_GetItemRect($hListView, $aLV_Click_Info[0], 2)
            Case Else ; On SubItem
                $aLV_Rect_Info = _GUICtrlListView_GetSubItemRect($hListView, $aLV_Click_Info[0], $aLV_Click_Info[1])
        EndSwitch
        ; Create temporary edit
        $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aLV_Rect_Info[0] + 10, $aLV_Rect_Info[1] + 90, $aLV_Rect_Info[2] - $aLV_Rect_Info[0], $aLV_Rect_Info[3] - $aLV_Rect_Info[1], 0)
        GUICtrlSetState($hTmp_Edit, $GUI_FOCUS)

    EndIf

WEnd


func close()
    exit
EndFunc

Func Modo_ADM()

if not $hotkey Then
    $hotkey = true
    Global $pass=InputBox("Security", "Digite a senha para modo ADM","" , "*M")
    if $pass == "senha" Then
        MsgBox(0,"","Acesso ADM autorizado!!")
    Else
        MsgBox(0,"","Senha incorreta")
    EndIf
    $hotkey = false
EndIf

EndFunc


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hListView And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hListView)
        If $aLV_Click_Info[0] <> -1 Then $fDblClk = True
    EndIf
    Return $GUI_RUNDEFMSG

EndFunc

 

lines between 48 and 74

the lines in listview are with  white background color, how can i fix it?

 

 

1 minute ago, Melque_Lima said:

 

thanks for your support

 

Link to comment
Share on other sites

You can use _GUICtrlListView_SetTextBkColor() to change the background color of the list view rows/items; just add it under the _SetBkColor func call.
 

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