Jump to content

Listview - disable column resize


Recommended Posts

  • Moderators

yetrael,

A brute force method would be putting this (or something similar) in your While...WEnd loop:

If _GUICtrlListView_GetColumnWidth($hListView, 0) <> 150 Then _GUICtrlListView_SetColumnWidth($hListView, 0, 150)

But I am sure someone else will have a better idea.

Of course, you could always elect not to have headers in the ListView - and the question becomes moot!

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

get the listview header handle and disable it

you can still programatically adjust the header as this example shows

but it is not adjustable by the user

you can also do this with header subclassing, but only if you need to do other things with the header

as it's more code,a bother and a performance hit

#include <GUIConstantsEX.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("Disable column resize", 300, 200)

$cListView = GUICtrlCreateListView("Items List|SubItems", 10, 10, 280, 180, $LVS_REPORT, $WS_EX_CLIENTEDGE)
$hListView = GUICtrlGetHandle($cListView)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$hHeader = HWnd(_GUICtrlListView_GetHeader($hListView))
;take your pick
;WinSetState($hHeader, "", @SW_DISABLE)
ControlDisable($hGUI, "", $hHeader)

_GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($hListView, 1, $LVSCW_AUTOSIZE_USEHEADER)

For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, "Item" & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem" & $i, 1)
Next

GUISetState()
Sleep(1000)
For $i = 1 To 10
    Sleep(10)
    _GUICtrlListView_AddItem($hListView, "Item" & $i * 10000)
    _GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem" & $i *1000, 1)
    _GUICtrlListView_SetColumnWidth($hListView, 1, $LVSCW_AUTOSIZE_USEHEADER)
Next


Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Edited by rover

I see fascists...

Link to comment
Share on other sites

Thanks a lot rover, i'll take the second one... think i missed it, when i searched the forum...

And there is another question, the colums are fixed, but there is still the resize cursor, when the mouse is moved to the edge of a column... is there a way to disable it, too? In the other thread this question was also discussed, but they didn't find a solution... any ideas?

i could disable the header, like rover said, but i like to sort the columns...

Edited by yetrael
Link to comment
Share on other sites

Thanks a lot rover, i'll take the second one... think i missed it, when i searched the forum...

And there is another question, the colums are fixed, but there is still the resize cursor, when the mouse is moved to the edge of a column... is there a way to disable it, too? In the other thread this question was also discussed, but they didn't find a solution... any ideas?

i could disable the header, like rover said, but i like to sort the columns...

you'll have to subclass the header for that

a modified _GUICtrlListView_RegisterSortCallBack help file example

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
;#include <WinAPI.au3>


Opt('MustDeclareVars', 1)

Global $hListView, $hListView2, $hHeader1, $hHeader2
Global Const $HDN_FIRST = -300
Global Const $HDN_ITEMCHANGINGA = $HDN_FIRST - 0
Global $wProcOld, $wProcNew

_Example2()

Func _Example2()
    Local $hImage, $aIcons[3] = [0, 3, 6]
    Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
    Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER)

    GUICreate("ListView Sort Treat Numbers as Strings", 300, 200, 100)

    $hListView = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180, -1, $iExWindowStyle)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle)
    $hHeader1 = HWnd(_GUICtrlListView_GetHeader($hListView))

    ; Load images
    $hImage = _GUIImageList_Create(18, 18, 5, 3)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -7)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -12)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -3)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -4)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -5)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -6)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -9)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -10)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -11)
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    _AddRow($hListView, "ABC|000666|10.05.2004", $aIcons)
    _AddRow($hListView, "DEF|444|11.05.2005", $aIcons, 1)
    _AddRow($hListView, "CDE|555|12.05.2004", $aIcons, 2)
    
    $wProcNew = DllCallbackRegister("_HeaderWindowProc", "ptr", "hwnd;uint;wparam;lparam")
    $wProcOld = _WinAPI_SetWindowLong($hHeader1, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
    GUISetState()

    GUICreate("ListView Sort Treat Numbers as Numbers", 300, 200, 400)

    $hListView2 = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180, -1, $iExWindowStyle)
    _GUICtrlListView_SetExtendedListViewStyle($hListView2, $iExListViewStyle)
    $hHeader2 = HWnd(_GUICtrlListView_GetHeader($hListView2))
    _GUICtrlListView_SetImageList($hListView2, $hImage, 1)

    _AddRow($hListView2, "ABC|000666|10.05.2004", $aIcons)
    _AddRow($hListView2, "DEF|444|11.05.2005", $aIcons, 1)
    _AddRow($hListView2, "CDE|555|12.05.2004", $aIcons, 2)

    _WinAPI_SetWindowLong($hHeader2, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
    GUISetState()

    _GUICtrlListView_RegisterSortCallBack($hListView, False)
    _GUICtrlListView_RegisterSortCallBack($hListView2)
    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    _GUICtrlListView_UnRegisterSortCallBack($hListView)
    _GUICtrlListView_UnRegisterSortCallBack($hListView2)
    GUIRegisterMsg($WM_NOTIFY, "")
    
    ; required on exit if subclassing
    If $wProcOld Then
        _WinAPI_SetWindowLong($hHeader1, $GWL_WNDPROC, $wProcOld)
        _WinAPI_SetWindowLong($hHeader2, $GWL_WNDPROC, $wProcOld)
    EndIf
    ; Delete callback function
    If $wProcNew Then DllCallbackFree($wProcNew)
    Exit
    
EndFunc   ;==>_Example2

Func _AddRow($hWnd, $sItem, $aIcons, $iPlus = 0)
    Local $aItem = StringSplit($sItem, "|")
    Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], $aIcons[0] + $iPlus, _GUICtrlListView_GetItemCount($hWnd) + 9999)
    _GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE_USEHEADER)

    For $x = 2 To $aItem[0]
        _GUICtrlListView_AddSubItem($hWnd, $iIndex, $aItem[$x], $x - 1, $aIcons[$x - 1] + $iPlus)
        _GUICtrlListView_SetColumnWidth($hWnd, $x - 1, $LVSCW_AUTOSIZE)
    Next
EndFunc   ;==>_AddRow

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $hWndListView2

    $hWndListView = $hListView
    $hWndListView2 = $hListView2
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    If Not IsHWnd($hListView2) Then $hWndListView2 = GUICtrlGetHandle($hListView2)
    
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hHeader1, $hHeader2
            Switch $iCode
                Case $HDN_ITEMCHANGINGA, $HDN_ITEMCHANGINGW
                     Return 1
            EndSwitch
        Case $hWndListView, $hWndListView2
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)

                    ; Kick off the sort callback
                    _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
                    ; No return value
            EndSwitch
    EndSwitch
    Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

; subclass function
Func _HeaderWindowProc($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    ;Local Const $WM_LBUTTONDOWN = 0x201
    Switch $hWnd
        Case $hHeader1, $hHeader2
            Switch $iMsg
                Case $WM_SETCURSOR;, $WM_LBUTTONDOWN
                    Return 0
            EndSwitch
    EndSwitch

    ;pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $wParam, $lParam)
EndFunc
Edited by rover

I see fascists...

Link to comment
Share on other sites

  • 5 years later...

you'll have to subclass the header for that

a modified _GUICtrlListView_RegisterSortCallBack help file example

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
;#include <WinAPI.au3>


Opt('MustDeclareVars', 1)

Global $hListView, $hListView2, $hHeader1, $hHeader2
Global Const $HDN_FIRST = -300
Global Const $HDN_ITEMCHANGINGA = $HDN_FIRST - 0
Global $wProcOld, $wProcNew

_Example2()

Func _Example2()
    Local $hImage, $aIcons[3] = [0, 3, 6]
    Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
    Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER)

    GUICreate("ListView Sort Treat Numbers as Strings", 300, 200, 100)

    $hListView = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180, -1, $iExWindowStyle)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle)
    $hHeader1 = HWnd(_GUICtrlListView_GetHeader($hListView))

    ; Load images
    $hImage = _GUIImageList_Create(18, 18, 5, 3)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -7)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -12)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -3)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -4)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -5)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -6)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -9)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -10)
    _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -11)
    _GUICtrlListView_SetImageList($hListView, $hImage, 1)

    _AddRow($hListView, "ABC|000666|10.05.2004", $aIcons)
    _AddRow($hListView, "DEF|444|11.05.2005", $aIcons, 1)
    _AddRow($hListView, "CDE|555|12.05.2004", $aIcons, 2)
    
    $wProcNew = DllCallbackRegister("_HeaderWindowProc", "ptr", "hwnd;uint;wparam;lparam")
    $wProcOld = _WinAPI_SetWindowLong($hHeader1, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
    GUISetState()

    GUICreate("ListView Sort Treat Numbers as Numbers", 300, 200, 400)

    $hListView2 = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180, -1, $iExWindowStyle)
    _GUICtrlListView_SetExtendedListViewStyle($hListView2, $iExListViewStyle)
    $hHeader2 = HWnd(_GUICtrlListView_GetHeader($hListView2))
    _GUICtrlListView_SetImageList($hListView2, $hImage, 1)

    _AddRow($hListView2, "ABC|000666|10.05.2004", $aIcons)
    _AddRow($hListView2, "DEF|444|11.05.2005", $aIcons, 1)
    _AddRow($hListView2, "CDE|555|12.05.2004", $aIcons, 2)

    _WinAPI_SetWindowLong($hHeader2, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
    GUISetState()

    _GUICtrlListView_RegisterSortCallBack($hListView, False)
    _GUICtrlListView_RegisterSortCallBack($hListView2)
    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

    _GUICtrlListView_UnRegisterSortCallBack($hListView)
    _GUICtrlListView_UnRegisterSortCallBack($hListView2)
    GUIRegisterMsg($WM_NOTIFY, "")
    
    ; required on exit if subclassing
    If $wProcOld Then
        _WinAPI_SetWindowLong($hHeader1, $GWL_WNDPROC, $wProcOld)
        _WinAPI_SetWindowLong($hHeader2, $GWL_WNDPROC, $wProcOld)
    EndIf
    ; Delete callback function
    If $wProcNew Then DllCallbackFree($wProcNew)
    Exit
    
EndFunc   ;==>_Example2

Func _AddRow($hWnd, $sItem, $aIcons, $iPlus = 0)
    Local $aItem = StringSplit($sItem, "|")
    Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], $aIcons[0] + $iPlus, _GUICtrlListView_GetItemCount($hWnd) + 9999)
    _GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE_USEHEADER)

    For $x = 2 To $aItem[0]
        _GUICtrlListView_AddSubItem($hWnd, $iIndex, $aItem[$x], $x - 1, $aIcons[$x - 1] + $iPlus)
        _GUICtrlListView_SetColumnWidth($hWnd, $x - 1, $LVSCW_AUTOSIZE)
    Next
EndFunc   ;==>_AddRow

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $hWndListView2

    $hWndListView = $hListView
    $hWndListView2 = $hListView2
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    If Not IsHWnd($hListView2) Then $hWndListView2 = GUICtrlGetHandle($hListView2)
    
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hHeader1, $hHeader2
            Switch $iCode
                Case $HDN_ITEMCHANGINGA, $HDN_ITEMCHANGINGW
                     Return 1
            EndSwitch
        Case $hWndListView, $hWndListView2
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)

                    ; Kick off the sort callback
                    _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem"))
                    ; No return value
            EndSwitch
    EndSwitch
    Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

; subclass function
Func _HeaderWindowProc($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    ;Local Const $WM_LBUTTONDOWN = 0x201
    Switch $hWnd
        Case $hHeader1, $hHeader2
            Switch $iMsg
                Case $WM_SETCURSOR;, $WM_LBUTTONDOWN
                    Return 0
            EndSwitch
    EndSwitch

    ;pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $wParam, $lParam)
EndFunc

Hi rover,

I have tested this code snippet in AutoIt v3.3.10.2 and ran a few problems.

The first was that "$HDN_FIRST was previously declared as a 'Const'" and thus prevented from execution;

the second was that by commenting-out that line, and then executing this script, the column headers can still be resized, it's just that only the Resize Cursor won't be shown during the resizing.

I am looking for a solution similiar to this topic, except that I have already resized the columns of each ListViewItem in a ListView, but would like to prevent users from resizing but also enable users to click-and-sort columns. (I used the forum search and came across this thread to get a solution). Any suggestions are welcome.

Edited by poila
Link to comment
Share on other sites

  • Moderators

poila,

rover has not been around for a while, so you are unlikely to get an answer. And trying to run 5 year old code usually poses problems as the language has changed so much in the intervening period - this is why we discourage necro-posting and would much prefer you to open a new thread with a link to the old one. ;)

Here is a pretty simple script showing how to prevent header resize but still allow sorting:

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

Global $g_bSortSense = False

$hGUI = GUICreate("ListView Fix Column Width", 400, 300)
$cListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 2, 2, 394, 268)

For $i = 1 To 10
    GUICtrlCreateListViewItem(Random(0, 10, 1) & "|" & Random(0, 10, 1) & "|" & Random(0, 10, 1) & "|" & Random(0, 10, 1), $cListView)
Next

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

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

    ; Get details of message
    Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)
    ; Look for header resize code
    $iCode = DllStructGetData($tNMHEADER, "Code")
    Switch $iCode
        Case $HDN_BEGINTRACKW
            ; Prevent resizing
            Return True
        Case $LVN_COLUMNCLICK
            ; Sort column
            $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
            $iCol = DllStructGetData($tInfo, "SubItem")
            _GUICtrlListView_SimpleSort($cListView, $g_bSortSense, $iCol)
    EndSwitch

EndFunc
Alas, you still get the "resize" cursor - I never managed to find out how to get rid of that without subclassing. :(

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

poila,

rover has not been around for a while, so you are unlikely to get an answer. And trying to run 5 year old code usually poses problems as the language has changed so much in the intervening period - this is why we discourage necro-posting and would much prefer you to open a new thread with a link to the old one. ;)

Here is a pretty simple script showing how to prevent header resize but still allow sorting:

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

Global $g_bSortSense = False

$hGUI = GUICreate("ListView Fix Column Width", 400, 300)
$cListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 2, 2, 394, 268)

For $i = 1 To 10
    GUICtrlCreateListViewItem(Random(0, 10, 1) & "|" & Random(0, 10, 1) & "|" & Random(0, 10, 1) & "|" & Random(0, 10, 1), $cListView)
Next

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

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

    ; Get details of message
    Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)
    ; Look for header resize code
    $iCode = DllStructGetData($tNMHEADER, "Code")
    Switch $iCode
        Case $HDN_BEGINTRACKW
            ; Prevent resizing
            Return True
        Case $LVN_COLUMNCLICK
            ; Sort column
            $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
            $iCol = DllStructGetData($tInfo, "SubItem")
            _GUICtrlListView_SimpleSort($cListView, $g_bSortSense, $iCol)
    EndSwitch

EndFunc
Alas, you still get the "resize" cursor - I never managed to find out how to get rid of that without subclassing. :(

M23

 

Thank you very much Melba, your code save me a lot :D

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