Page 1 of 1

[ListView] Preventing users from resizing columns widths

Posted: 02 Aug 2021, 03:58
by jNizM
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)
}

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

Posted: 02 Aug 2021, 11:49
by kczx3
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()

Re: [ListView] Preventing users from resizing columns widths

Posted: 03 Aug 2021, 04:01
by jNizM
Added your suggestion :thumbup:

Re: [ListView] Preventing users from resizing columns widths

Posted: 01 Feb 2023, 13:36
by iPhilip
@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!