Jump to content

Set Color Line _GUICtrlListView


asdf22
 Share

Recommended Posts

How to set BkColor only on line 3 in _GUICtrlListView

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>

Global $hGUIForm, $sHeaderText, $iItemIndex

$hGUIForm = GUICreate("_GUICtrlListView", 600, 300)
$sHeaderText = "Column1|Column2|Column3|Column4"

$hListView = _GUICtrlListView_Create($hGUIForm, $sHeaderText, 5, 5, 590, 290)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES))

$iItemIndex =  _GUICtrlListView_AddItem($hListView, 1)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "aa_1", 1)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "bb_1", 2)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "cc_1", 3)

$iItemIndex = _GUICtrlListView_AddItem($hListView, 2)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "aa_2", 1)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "bb_2", 2)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "cc_2", 3)

$iItemIndex =_GUICtrlListView_AddItem($hListView, 3)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "aa_3", 1)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "bb_3", 2)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "cc_3", 3)

GUISetState(@SW_SHOW)

Dim $msg
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect           
WEnd
GUIDelete($hGUIForm)
Exit
Edited by asdf22
Link to comment
Share on other sites

@Zedna, thanks

I didn't understood what happens in the last code and my english is BAD

I need the function ChangeColorLine() which sets the colour of the line which is marked.

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>

Global $hGUIForm, $sHeaderText, $iItemIndex, $button_ChangeColorLine

$hGUIForm = GUICreate("_GUICtrlListView", 600, 300)
$button_ChangeColorLine = GUICtrlCreateButton("ChangeColorLine", 350, 10, 90, 23)

$sHeaderText = "Column1|Column2|Column3|Column4"

$hListView = _GUICtrlListView_Create($hGUIForm, $sHeaderText, 5, 5, 320, 290)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES))

$iItemIndex =  _GUICtrlListView_AddItem($hListView, 1)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "aa_1", 1)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "bb_1", 2)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "cc_1", 3)

$iItemIndex = _GUICtrlListView_AddItem($hListView, 2)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "aa_2", 1)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "bb_2", 2)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "cc_2", 3)

$iItemIndex =_GUICtrlListView_AddItem($hListView, 3)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "aa_3", 1)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "bb_3", 2)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "cc_3", 3)

GUISetState(@SW_SHOW)

Func ChangeColorLine()
    ; code
EndFunc



Dim $msg
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button_ChangeColorLine
            ChangeColorLine()
    EndSelect         
WEnd
GUIDelete($hGUIForm)
Exit
Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
#include <Array.au3>

Global $hGUIForm, $sHeaderText, $iItemIndex, $button_ChangeColorLine
Global $aColoredLines[1] = [-1]

$hGUIForm = GUICreate("_GUICtrlListView", 600, 300)
$button_ChangeColorLine = GUICtrlCreateButton("ChangeColorLine", 350, 10, 90, 23)

$sHeaderText = "Column1|Column2|Column3|Column4"

$hListView = _GUICtrlListView_Create($hGUIForm, $sHeaderText, 5, 5, 320, 290)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES))

$iItemIndex =  _GUICtrlListView_AddItem($hListView, 1)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "aa_1", 1)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "bb_1", 2)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "cc_1", 3)

$iItemIndex = _GUICtrlListView_AddItem($hListView, 2)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "aa_2", 1)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "bb_2", 2)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "cc_2", 3)

$iItemIndex =_GUICtrlListView_AddItem($hListView, 3)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "aa_3", 1)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "bb_3", 2)
_GUICtrlListView_AddSubItem($hListView, $iItemIndex, "cc_3", 3)

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

Func ChangeColorLine()
 $selected = _GUICtrlListView_GetNextItem($hListView)
 _ArrayAdd($aColoredLines, $selected)
EndFunc

Dim $msg
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button_ChangeColorLine
            ChangeColorLine()
    EndSelect         
WEnd
GUIDelete($hGUIForm)
Exit

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 $hListView
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    Local $tCustDraw = DllStructCreate('hwnd hwndFrom;int idFrom;int code;' & _
                                        'dword DrawStage;hwnd hdc;long rect[4];dword ItemSpec;int ItemState;dword Itemlparam;' & _
                                        'dword clrText;dword clrTextBk;int SubItem;' & _
                                        'dword ItemType;dword clrFace;int IconEffect;int IconPhase;int PartID;int StateID;long rectText[4];int Align', _ ;winxp or later
                                        $lParam)
                    
                    Local $iDrawStage = DllStructGetData($tCustDraw, 'DrawStage')
                    
                    If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
                    
                    Local $iItem = DllStructGetData($tCustDraw, 'ItemSpec')
                    
                If _ArraySearch($aColoredLines, $iItem) > 0 Then
                            DllStructSetData($tCustDraw, 'clrTextBk', 0xFFFF00)
                            Return $CDRF_NOTIFYITEMDRAW
                    EndIf
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

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