Jump to content
Sign in to follow this  
asdf22

Set Color Line _GUICtrlListView

Recommended Posts

asdf22

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

Share this post


Link to post
Share on other sites
asdf22

@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

Share this post


Link to post
Share on other sites
Zedna

#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

Share this post


Link to post
Share on other sites
asdf22

@Zedna, Thank you very much. Greetings from Bulgaria. ^_^

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.