Jump to content
AutoBert

[solved] Set HeaderColumn Color in ListView

Recommended Posts

BBs19,

Alas, no.

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

 

Share this post


Link to post
Share on other sites
Posted (edited)
On 10/29/2017 at 7:44 PM, BBs19 said:

Hi Melba, do you also know a way to color the background that is behind the headers? If I resize the headers, the background of the main ListView seems to be white :(

 

LV.PNG

One trick is to add an empty column at the end and resize it dynamically:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <GuiListView.au3>

Global Const $tagNMCUSTOMDRAW = "struct;" & $tagNMHDR & ";dword dwDrawStage;handle hdc;" & $tagRECT & _
                                ";dword_ptr dwItemSpec;uint uItemState;lparam lItemlParam;endstruct"

;                        Title    TextCol   BkCol         - colours in BGR
Global $aHdrData[][] = [["Tom",   0x000000, 0x00FFFF], _
                        ["Dick",  0x00FFFF, 0x0000FF], _
                        ["Harry", 0xFF0000, 0xFFCCCC], _
                        ["", 0xFF0000, 0xFFCCCC] _ ;"fill" column
                        ]
Global $colCount = UBound($aHdrData)


$hGUI = GUICreate("Set Listview Header Colour ", 500, 300)
$cListView = GUICtrlCreateListView(_ArrayToString(_ArrayExtract($aHdrData, 0, $colCount-2, 0, 0)), 10, 10, 480, 280)
$hListView = GUICtrlGetHandle($cListView)
_GUICtrlListView_SetExtendedListViewStyle($cListView, $LVS_EX_FULLROWSELECT) ; BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

;Get header handle
Global $hHeader = _GUICtrlListView_GetHeader($cListView)

; Get the font of the Header control (credit KaFu)
Local $hDC = _WinAPI_GetDC($hHeader)
Local $hFont = _SendMessage($hHeader, $WM_GETFONT)
Local $hObject = _WinAPI_SelectObject($hDC, $hFont)
Local $tLogFont = DllStructCreate($tagLOGFONT)

_WinAPI_GetObject($hFont, DllStructGetSize($tLogFont), DllStructGetPtr($tLogFont))
_WinAPI_SelectObject($hDC, $hObject)
_WinAPI_ReleaseDC($hHeader, $hDC)

Local $iWeight = DllStructGetData( $tLogFont, "Weight" )               ; Bold
DllStructSetData( $tLogFont, "Weight", BitOR( $iWeight, $FW_BOLD ) )
$hHdrFont = _WinAPI_CreateFontIndirect( $tLogFont )

For $i = 1 To 15
    _GUICtrlListView_AddItem($cListView, "Item" & $i)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 1)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 2)
Next

For $i = 0 To  $colCount - 2
    _GUICtrlListView_SetColumnWidth($cListView, $i, $LVSCW_AUTOSIZE_USEHEADER)
Next

_GUICtrlListView_AddColumn($cListView, "") ;this will prevent last visible column from filling up the remaining width
_GUICtrlListView_SetColumnWidth($cListView, $colCount - 1, 0)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return

    Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)
    If HWnd( DllStructGetData($tNMHEADER, "hWndFrom")) = $hHeader Then
        Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
        Switch $iCode

            Case $HDN_BEGINTRACKW
                Local $iCol = DllStructGetData($tNMHEADER, "Item")
                If $iCol = $colCount - 1 Then
                    ; Prevent resizing of last (empty) column
                    Return True
                Else
                    ; Allow resizing
                    Return False
                EndIf

            Case $HDN_TRACKW, $HDN_ENDTRACKW
                Local $pos = ControlGetPos($hGUI, "", $cListView)
                Local Static $scrollbarWidth = _WinAPI_GetSystemMetrics($SM_CXVSCROLL)
                Local $rectFirst = _GUICtrlListView_GetItemRect($hListView, 0)
                Local $rectLast = _GUICtrlListView_GetSubItemRect($hListView, _GUICtrlListView_GetItemCount($cListView) - 1, $colCount - 2, 0) ;rect of last subitem of last item 
                Local $sw = ($rectFirst[1] < 0 Or $rectLast[3] > $pos[3]) ? $scrollbarWidth : 0 ;scrollbar shown?
                Local $w = $pos[2] - $rectLast[2] - $sw - 4 ;not sure what the 4 is for
                GUICtrlSendMsg( $cListView, $LVM_SETCOLUMNWIDTH, $colCount-1, $w > 0 ? $w : 0);resize last (empty) column

            Case $NM_CUSTOMDRAW

                Local $tNMCustomDraw = DllStructCreate($tagNMCUSTOMDRAW, $lParam)
                Local $dwDrawStage = DllStructGetData($tNMCustomDraw, "dwDrawStage")
                Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                    Case $CDDS_PREPAINT ; Before the paint cycle begins
                        Return $CDRF_NOTIFYITEMDRAW ; Notify parent window of any item related drawing operations

                    Case $CDDS_ITEMPREPAINT ; Before an item is drawn: Default painting (frames and background)
                        Return $CDRF_NOTIFYPOSTPAINT ; Notify parent window of any post item related drawing operations

                    Case $CDDS_ITEMPOSTPAINT ; After an item is drawn: Custom painting (item texts)
                        Local $tRECT = DllStructCreate($tagRECT)
                        Local $iIndex = DllStructGetData($tNMCustomDraw, "dwItemSpec") ; Item index
                        Local $hDC = DllStructGetData($tNMCustomDraw, "hdc") ; Device context
                        _WinAPI_SelectObject($hDC, $hHdrFont) ; Set text font
                        _WinAPI_SetBkMode($hDC, $TRANSPARENT) ; Transparent background
                        _WinAPI_SetTextColor( $hDC, $aHdrData[$iIndex][1]) ; Set text colour
                        ; Get header section size
                        DllStructSetData($tRECT, 1, DllStructGetData($tNMCustomDraw, 6) + 1)
                        DllStructSetData($tRECT, 2, DllStructGetData($tNMCustomDraw, 7) + 1)
                        DllStructSetData($tRECT, 3, DllStructGetData($tNMCustomDraw, 8) - ($iIndex = $colCount - 1 ? 0 : 2))
                        DllStructSetData($tRECT, 4, DllStructGetData($tNMCustomDraw, 9) - 2)
                        ; Set and draw back colour
                        Local $hBrush = _WinAPI_CreateSolidBrush($aHdrData[$iIndex][2])
                        _WinAPI_FillRect($hDC, $tRECT, $hBrush)
                        ; Write text
                        If $iIndex < _GUICtrlListView_GetColumnCount($cListView) Then
                            _WinAPI_DrawText ( $hDC, $aHdrData[$iIndex][0], $tRECT, $DT_CENTER + $DT_VCENTER )
                        EndIf
                        Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
                EndSwitch

        EndSwitch
    EndIf

EndFunc   ;==>_WM_NOTIFY

Or disallow resizing last column to the size smaller than the width of the list

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <GuiListView.au3>

Global Const $tagNMCUSTOMDRAW = "struct;" & $tagNMHDR & ";dword dwDrawStage;handle hdc;" & $tagRECT & _
                                ";dword_ptr dwItemSpec;uint uItemState;lparam lItemlParam;endstruct"

;                        Title    TextCol   BkCol         - colours in BGR
Global $aHdrData[][] = [["Tom",   0x000000, 0x00FFFF], _
                        ["Dick",  0x00FFFF, 0x0000FF], _
                        ["Harry", 0xFF0000, 0xFFCCCC] _
                        ]
Global $colCount = UBound($aHdrData)


$hGUI = GUICreate("Set Listview Header Colour ", 500, 300)
$cListView = GUICtrlCreateListView(_ArrayToString(_ArrayExtract($aHdrData, 0, $colCount-1, 0, 0)), 10, 10, 480, 280)
$hListView = GUICtrlGetHandle($cListView)
_GUICtrlListView_SetExtendedListViewStyle($cListView, $LVS_EX_FULLROWSELECT) ; BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

;Get header handle
Global $hHeader = _GUICtrlListView_GetHeader($cListView)

; Get the font of the Header control (credit KaFu)
Local $hDC = _WinAPI_GetDC($hHeader)
Local $hFont = _SendMessage($hHeader, $WM_GETFONT)
Local $hObject = _WinAPI_SelectObject($hDC, $hFont)
Local $tLogFont = DllStructCreate($tagLOGFONT)

_WinAPI_GetObject($hFont, DllStructGetSize($tLogFont), DllStructGetPtr($tLogFont))
_WinAPI_SelectObject($hDC, $hObject)
_WinAPI_ReleaseDC($hHeader, $hDC)

Local $iWeight = DllStructGetData( $tLogFont, "Weight" )               ; Bold
DllStructSetData( $tLogFont, "Weight", BitOR( $iWeight, $FW_BOLD ) )
$hHdrFont = _WinAPI_CreateFontIndirect( $tLogFont )

For $i = 1 To 15
    _GUICtrlListView_AddItem($cListView, "Item" & $i)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 1)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 2)
Next

For $i = 0 To  $colCount - 1
    _GUICtrlListView_SetColumnWidth($cListView, $i, $LVSCW_AUTOSIZE_USEHEADER)
Next

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return

    Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)
    If HWnd( DllStructGetData($tNMHEADER, "hWndFrom")) = $hHeader Then
        Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
        Local Static $lastRect = 0
        Switch $iCode

            Case $HDN_TRACKW, $HDN_ENDTRACKW
                Local $pos = ControlGetPos($hGUI, "", $cListView)
                Local $rectLast = _GUICtrlListView_GetSubItemRect($hListView, _GUICtrlListView_GetItemCount($cListView) - 1, $colCount - 1, 0)
                If $pos[2] > $rectLast[2] Then
                    Local Static $scrollbarWidth = _WinAPI_GetSystemMetrics($SM_CXVSCROLL)
                    Local $rectFirst = _GUICtrlListView_GetItemRect($hListView, 0)
                    Local $sw = ($rectFirst[1] < 0 Or $rectLast[3] > $pos[3]) ? $scrollbarWidth : 0
                    GUICtrlSendMsg( $cListView, $LVM_SETCOLUMNWIDTH, $colCount-1, $pos[2] - $rectLast[0] - $sw - 4);resize last column
                    Return True
                EndIf
            Case $NM_CUSTOMDRAW

                Local $tNMCustomDraw = DllStructCreate($tagNMCUSTOMDRAW, $lParam)
                Local $dwDrawStage = DllStructGetData($tNMCustomDraw, "dwDrawStage")
                Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                    Case $CDDS_PREPAINT ; Before the paint cycle begins
                        Return $CDRF_NOTIFYITEMDRAW ; Notify parent window of any item related drawing operations

                    Case $CDDS_ITEMPREPAINT ; Before an item is drawn: Default painting (frames and background)
                        Return $CDRF_NOTIFYPOSTPAINT ; Notify parent window of any post item related drawing operations

                    Case $CDDS_ITEMPOSTPAINT ; After an item is drawn: Custom painting (item texts)
                        Local $tRECT = DllStructCreate($tagRECT)
                        Local $iIndex = DllStructGetData($tNMCustomDraw, "dwItemSpec") ; Item index
                        Local $hDC = DllStructGetData($tNMCustomDraw, "hdc") ; Device context
                        _WinAPI_SelectObject($hDC, $hHdrFont) ; Set text font
                        _WinAPI_SetBkMode($hDC, $TRANSPARENT) ; Transparent background
                        _WinAPI_SetTextColor( $hDC, $aHdrData[$iIndex][1]) ; Set text colour
                        ; Get header section size
                        DllStructSetData($tRECT, 1, DllStructGetData($tNMCustomDraw, 6) + 1)
                        DllStructSetData($tRECT, 2, DllStructGetData($tNMCustomDraw, 7) + 1)
                        DllStructSetData($tRECT, 3, DllStructGetData($tNMCustomDraw, 8) - 2)
                        DllStructSetData($tRECT, 4, DllStructGetData($tNMCustomDraw, 9) - 2)
                        ; Set and draw back colour
                        Local $hBrush = _WinAPI_CreateSolidBrush($aHdrData[$iIndex][2])
                        _WinAPI_FillRect($hDC, $tRECT, $hBrush)
                        ; Write text
                        If $iIndex < _GUICtrlListView_GetColumnCount($cListView) Then
                            _WinAPI_DrawText ( $hDC, $aHdrData[$iIndex][0], $tRECT, $DT_CENTER + $DT_VCENTER )
                        EndIf
                        Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
                EndSwitch

        EndSwitch
    EndIf

EndFunc   ;==>_WM_NOTIFY

 

One thing I can't figure out is why $HDN_TRACKW event is not firing while column divider is being dragged?

Also there must be a better way detect when vertical scrollbar is shown, I'm using first item and last item coordinates to detect if they are outside of listview or not.

Edited by VAN0

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By DrJohn
      Hi.  Attempting to catch and process a keystroke in a GUI window.  Here's the code:
      ; ---------------------------------------------------------------------- ; | Library includes ; ---------------------------------------------------------------------- #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> #include <WinAPISys.au3> #include <WinAPIvkeysConstants.au3> #include <GuiButton.au3> global $g_MainGUI CreateMainGUI() ; ---------------------------------------------------------------------- func CreateMainGUI() $g_MainGUI = GUICreate("Test", 600, 600, -1, -1) ; $b = _GUICtrlButton_Create($g_MainGUI, "Foo", 10, 10, 100, 30) ; <--- Line #21 $lv = _GUICtrlListView_Create($g_MainGUI, "", 50, 50, 100, 100) ; <--- Line #22 GUISetState(@SW_SHOW, $g_MainGUI) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") do ; until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() endfunc ; ---------------------------------------------------------------------- func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) local $hdr = DllStructCreate($tagNMHDR, $lParam) local $from = HWnd(DllStructGetData($hdr, "hWndFrom")) local $id = DllStructGetData($hdr, "IDFrom") local $event = DllStructGetData($hdr, "Code") ; Exit on [ctrl-Q] if ($event = $LVN_KEYDOWN) then $info = DllStructCreate($tagNMLVKEYDOWN, $lParam) $vkey = DllStructGetData($info, "VKey") if ($vkey = 0x51) and BitAND(_WinAPI_GetKeyState($VK_CONTROL), 0x8000) then ConsoleWrite('[ctrl-Q]' & @CRLF) ; <--- Line #48 _SendMessage($g_MainGUI, $GUI_EVENT_CLOSE) endif endif return $GUI_RUNDEFMSG endfunc There are two things about this code that don't work the way I expected, and I've been unable to figure out why:
      1)
      As it stands, the code creates a GUI window, then a ListView.  If I run it then immediately press ctrl-Q, the keystroke triggers WM_NOTIFY().  I know that because if I run in SciTE, '[ctrl-Q]' appears in the console window, so the ConsoleWrite() call on line #48 must have executed.
      If I comment out the _GUICtrlListView_Create() call on line #22 and uncomment line #21 so that a Button is created instead, then run it, WM_NOTIFY() is never triggered.
      Why the difference?  Doesn't the GUIRegisterMsg() call register WM_NOTIFY on behalf of the parent GUI?  Why does it work with one control type, but not the other?
      2)
      In the case with the ListView control, where it does catch the ctrl-Q, it executes _SendMessage($g_MainGUI, $GUI_EVENT_CLOSE).  In my simple mind, I'd have thought that would send the $GUI_EVENT_CLOSE message to the main GUI and cause it to exit the do/until loop.
      But evidently not?  Because it doesn't.
      Thanks in advance.  Just when I think I understand ...
      /John
    • By Irios
      I have several context menus that's been built using _GUICtrlMenu_CreatePopup() and _GUICtrlMenu_AddMenuItem().
      When using _GUICtrlMenu_CreatePopup() it returns the identifier of the clicked item, sure. But it blocks the main loop while the menu is open.
      When using _GUICtrlMenu_CreatePopup($MNS_MODELESS) it returns immediately (of course), but I cannot figure out how/where to read the item that was clicked. Is there a Windows Message (WM) somewhere that is triggered? I've spend an entire day trying to figure out how to do this, but I'm not getting anywhere. My google fu is depleted (I must have tried like hundreds of script variations today), I'm about to smash my keyboard and just go to bed, and abandon the entire endeavor of making pretty menus and go back to using Koda and forget about using menu icons, colors,  etc.
      Anyone wanna help me out with how to read the clicked item? Before I smash my keyboard, please...
       
      Example script here:
       
      #include <GuiMenu.au3> #include <WinAPIError.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> GUIRegisterMsg($WM_CONTEXTMENU, "_WM_CONTEXTMENU") Global $idMenuItem = 10000, $counter = 0 Global $hGUI = GUICreate("Menu test", 400, 300) Global $hListview = GUICtrlCreateListView("", 2, 2, 396, 200) GUISetState(@SW_SHOW) ;~ Global $hMenuContext = _GUICtrlMenu_CreatePopup() Global $hMenuContext = _GUICtrlMenu_CreatePopup($MNS_MODELESS) _GUICtrlMenu_AddMenuItem($hMenuContext, "Menu item", $idMenuItem) Global $hTimer = TimerInit() Do If TimerDiff($hTimer)>200 Then $counter += 1 ConsoleWrite($counter & " " ) $hTimer = TimerInit() EndIf Until GUIGetMsg() = $GUI_EVENT_CLOSE Exit Func _WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Switch $wParam Case GUICtrlGetHandle($hListview) ConsoleWrite( @CRLF & "_GUICtrlMenu_TrackPopupMenu = " & _GUICtrlMenu_TrackPopupMenu($hMenuContext, $wParam, -1, -1, 1, 1, 2) & @CRLF) EndSwitch EndFunc  
       
    • By Skysnake
      I thought I remembered this from somewhere, then I searched, but cannot find which I am looking for...
      How to display additional, hidden ListViewItem text in a popup?
      I thought I saw a Style element that does that, but I cannot find it
      Just point me in the right direction please?
    • By Skysnake
      Hi
      Best example I could find is here
      ::/html/libfunctions/_GUICtrlTreeView_ClickItem.htm
      The way I understand this, the standard Windows messages, such as Left/Right Click etc are covered by AutoIt macros, but the real power is locked up inside this WM_NOTIFY .  I have tried, but I am not even sure I understand what I am looking at.
      I need help understanding this.  What I am looking for is Help file or Tutorial explaining how this works?  
      Perhaps if there is a script showing both the working of an AutoIt macro and the WM_NOTIFY  in action, it would help.
      Right now I am so lost, I do not even know what are the right questions to ask.  One issue I have is on ListViews, how to combine the "Click" of a line with a standard Switch loop?  Like users clicks a line, then get the loop to detect the click and ;do something ...
      Any ideas?
      Skysnake
    • By PINTO1927
      Hello guys,
      I'm working with a simple script, complementing a GUICtrlCreateListView which has 5 columns. I would order the first column so that the numbers are decreasing.
      #include <GuiListView.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <StructureConstants.au3> Opt('MustDeclareVars', 1) Global $search_LV, $B_DESCENDING GUICreate("ListView Sort by Column Click", 400, 300) $search_LV = GUICtrlCreateListView("String|Number|String", 2, 2, 394, 268) GUICtrlSendMsg($search_LV, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($search_LV, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("line4|5|1A", $search_LV) GUICtrlCreateListViewItem("line5|4.50 |1B", $search_LV) GUICtrlCreateListViewItem("line10|4.0 |2C", $search_LV) GUICtrlCreateListViewItem("line3|23|01", $search_LV) GUICtrlCreateListViewItem("line2|0.34560 |09", $search_LV) GUICtrlCreateListViewItem("line1|1.0 |7A", $search_LV) GUICtrlCreateListViewItem("line1|0.1 |8C", $search_LV) GUICtrlCreateListViewItem("line1|97|5B", $search_LV) GUICtrlCreateListViewItem("line1|910|9B", $search_LV) GUICtrlCreateListViewItem("line1|99|11", $search_LV) GUICtrlCreateListViewItem("line1|990.99|06", $search_LV) _GUICtrlListView_SetColumnWidth($search_LV, 0, 75) _GUICtrlListView_SetColumnWidth($search_LV, 1, 75) _GUICtrlListView_SetColumnWidth($search_LV, 2, 75) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;~ _GUICtrlListView_RegisterSortCallBack($search_LV, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $search_LV ; Kick off the sort callback ;~ _GUICtrlListView_SortItems($search_LV, GUICtrlGetState($search_LV)) ;~ _GUICtrlListView_UnRegisterSortCallBack($search_LV) EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $search_LV ;~ If Not IsHWnd($search_LV) Then $hWndListView = GUICtrlGetHandle($search_LV) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom ;~ Case $search_LV Case GUICtrlGetHandle($search_LV) Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked ConsoleWrite("Header geklickt" & @CRLF) Local $tInfo = DllStructCreate($tagNMLISTVIEW, $iLparam) _GUICtrlListView_UnRegisterSortCallBack($search_LV) Local $ColumnSorted = DllStructGetData($tInfo, 'SubItem') If $ColumnSorted = 1 Then ConsoleWrite('Numeric: ' & _GUICtrlListView_RegisterSortCallBack($search_LV, True) & @CRLF) Else ConsoleWrite('Literal: ' & _GUICtrlListView_RegisterSortCallBack($search_LV, False) & @CRLF) EndIf _GUICtrlListView_SortItems($search_LV, DllStructGetData($tInfo, 'SubItem')) EndSwitch EndSwitch EndFunc ;==>WM_NOTIFY Ordering the "String" column, you notice that the line "line10" is not ordered last. And 'possible to order the "String" column in descending order?
      thank you very much
×
×
  • Create New...