[ListView] Preventing users from resizing columns widths

Put simple Tips and Tricks that are not entire Tutorials in this forum
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

[ListView] Preventing users from resizing columns widths

02 Aug 2021, 03:58

Preventing users from resizing columns widths in ListView


Method 1:
Check for the HDN_ITEMCHANGING header control notifications code

Code: Select all

MyGui := Gui()
LV := MyGui.Add("ListView", "w300 r15 Grid -LV0x10", ["Column1", "Column2", "Column3"])
LV.OnNotify(HDN_ITEMCHANGINGW := -320, (*) => true)
MyGui.Show()



Method 2:
Send the HDS_NOSIZING header control style to the ListView

Code: Select all

MyGui := Gui()
LV := MyGui.Add("ListView", "w300 r15 Grid -LV0x10", ["Column1", "Column2", "Column3"])
LV_NoSizing(LV)
MyGui.Show()


LV_NoSizing(hListView)
{
	static LVM_FIRST     := 0x1000
	static LVM_GETHEADER := LVM_FIRST + 31
	static HDS_NOSIZING  := 0x0800

	hListViewHeader := SendMessage(LVM_GETHEADER, 0, 0, hListView)
	ControlSetStyle("+" . HDS_NOSIZING, hListViewHeader)
}
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: [v2][ListView] Preventing users from resizing columns widths

02 Aug 2021, 11:49

I'd probably recommend this instead:

Code: Select all

g := gui()
lv := g.add("ListView", "w300 r15 Grid -LV0x10", ["Column1", "Column2", "Column3"])
hdrHwnd := SendMessage(LVM_GETHEADER := 0x101F, 0, 0, lv)

ControlSetStyle("+" . HDS_NOSIZING := 0x800, hdrHwnd)

g.show()
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: [ListView] Preventing users from resizing columns widths

03 Aug 2021, 04:01

Added your suggestion :thumbup:
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
iPhilip
Posts: 822
Joined: 02 Oct 2013, 12:21

Re: [ListView] Preventing users from resizing columns widths

01 Feb 2023, 13:36

@jNizM, Just to expand on this tip, the code below shows how to prevent a user from resizing a specified set of columns.

Code: Select all

FrozenColumns := "2|3"

MyGui := Gui()
LV := MyGui.Add("ListView", "w300 r15 Grid -LV0x10", ["Column1", "Column2", "Column3", "Column4"])
LV.OnNotify(HDN_ITEMCHANGINGW := -320, (GuiControl, lParam) => NumGet(lParam, 3 * A_PtrSize, "Int") + 1 ~= FrozenColumns)
MyGui.Show()
Cheers!
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 7 guests