Jump to content

GUIListViewEx Help me to colour individual cells


Recommended Posts

  • Moderators

yoyodutheil,

Welcome to the AutoIt forums.

Look at the comments I have added to your  script:

#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListViewEx.au3>
#include <MsgBoxConstants.au3>
#include <Debug.au3>

Global $suivi_couleur[80]

$suivi_couleur[1] = '0x9400D3'
$suivi_couleur[2] = '0xFF1493'
$suivi_couleur[3] = '0x00BFFF'
$suivi_couleur[4] = '0x696969'
$suivi_couleur[5] = '0x1E90FF'
$suivi_couleur[6] = '0xB22222'
$suivi_couleur[7] = '0xFFFAF0'
$suivi_couleur[8] = '0x228B22'
$suivi_couleur[9] = '0xFF00FF'
$suivi_couleur[10] = '0xDCDCDC'
$suivi_couleur[11] = '0xF8F8FF'
$suivi_couleur[12] = '0xFFD700'
$suivi_couleur[13] = '0xDAA520'
$suivi_couleur[14] = '0x808080'
$suivi_couleur[15] = '0x008000'
$suivi_couleur[16] = '0xADFF2F'
$suivi_couleur[17] = '0xF0FFF0'
$suivi_couleur[18] = '0xFF69B4'
$suivi_couleur[19] = '0xCD5C5C'
$suivi_couleur[20] = '0x4B0082'

Example()

Func Example()
    Local $idListview

    GUICreate("ListView Set BkColor", 400, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 394, 268)
    _GUICtrlListView_AddColumn(-1, 'Fond', 80)
    _GUICtrlListView_AddColumn(-1, 'Text', 90)

    _GUIListViewEx_MsgRegister() ; You need to register various Windows messages for the UDF to work at all!! <<<<<<<<<<<<<<<<<<<<

    GUISetState(@SW_SHOW)
    Local $atext[10][2]
    $coul = 0
    For $l = 0 To 9
        For $c = 0 To 1
            $coul = $coul + 1
            $atext[$l][$c] = $suivi_couleur[$coul]
        Next
    Next
    _GUICtrlListView_AddArray($idListview, $atext) ; Add the content BEFORE initialising the ListView <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $lv_index = _GUIListViewEx_Init($idListview, $atext, 0, 0, True, 1 + 8 + 32)


    For $l = 0 To 9
        For $c = 0 To 1
            $couleur_fond= ";" & $atext[$l][$c]
            $iRet = _GUIListViewEx_SetColour($lv_index, $couleur_fond, $l, $c) ; You were adding a second leading ";" to the colour <<<<<<<<<
        Next
    Next

    Do

    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

Please ask if you have any questions.

And in future, please use the relevant UDF thread for any questions on my UDFs - that way I am sure to see them.

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

  • Moderators

yoyodutheil,

Glad I could help. Please do read the Guide file within the UDF download zip - it does go into some detail about what you have to do to get this pretty complex UDF to work as it should!

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

Hi, 

Now the problem is that in my code I use a wm_notify funtion. The question is wher to put the 

_GUIListViewEx_MsgRegister()

Here is my extract code for wm_notify when I put _GuiListviewEx_Msgregister()  in it ,the coloring of cell still working OK but tehe code in the WM_Notify does not work anymore.

Thank you

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


    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $operations_list_view
    If Not IsHWnd($operations_list_view) Then $hWndListView = GUICtrlGetHandle($operations_list_view)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
    $iIDFrom = DllStructGetData($tNMHDR, 'IDFrom')
    $iCode = DllStructGetData($tNMHDR, 'Code')

    Switch $hWndFrom
        Case $hWndListView
            If $iCode = $NM_CLICK Then
                $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                $index = DllStructGetData($tInfo, 'Index')

                $sub_index = DllStructGetData($tInfo, 'SubItem')

                _GUICtrlListView_GetItemTextString($operations_list_view, $index)

                $ligne_ope_text = _GUICtrlListView_GetItemTextString($operations_list_view, $index)
                $ligne_ope_click = 1
            EndIf
            If $iCode = $LVN_COLUMNCLICK Then         ; order listview operations
                $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                $sub_index = DllStructGetData($tInfo, 'SubItem')

                _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, $sub_index, True)
            EndIf
    EndSwitch

    Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

yoyodutheil,

As explained in the Guide to which I referred you earlier, if you have an existing message handler then you must NOT register the same message via the UDF and you need to call the related function in your own handler - usually as the final action:

Quote

You will need to register some Windows messages so that the UDF can intercept various key and mouse events and determine the correct actions to take. This is done via _GUIListViewEx_MsgRegister – note that if using coloured items, this function must be run before calling GUISetState to display the GUI in which the ListView appears. Registering WM_NOTIFY is needed for all UDF functions, WM_MOUSEMOVE and WM_LBUTTONUP are only needed if dragging, while WM_SYSCOMMAND just permits the use of the [X] to close the GUI immediately while editing.

 

For more advanced users: The UDF registers these 4 messages automatically – if you already have handlers for these messages in your script, do not register them again using the UDF function (set the relevant parameter to False) but call the relevant UDF handler function from within your existing handler. Note that the UDF handler should be called as the final action of the existing handler and the return value should be that returned from the UDF handler - this is particularly important when any colour functionality is used.

So use the _GUIRegMsg function as follows:

_GUIListViewEx_MsgRegister(False)

This will NOT register the WM_NOTIFY message, but will register all of the others the UDF requires. Then add the following as the final line of your own WM_NOTIFY handler, after removing the 2 existing Return lines:

_GUIListViewEx_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam)

Now your own handler should run and the UDF will follow on from there.

But I must ask why you are creating your own handler to sort the ListView - doing so other then by using the existing UDF functions will completely destroy the internal shadow array used by the UDF to track the ListView content and will result in the complete failure of your script - sooner rather then later.

You are already initialising the ListView to simplesort on header clicks by using the "1" parameter; you can programmatically simplesort a column using the _GUIListViewEx_SortCol function; and you can use your own sort function for any particular column by using the _GUIListViewEx_UserSort function. So I see no reason why you should require your own handler to sort anything at all!

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

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