[MS] How can I prevent the user from changing the widths of ListView columns? - devamazonaws.blogspot.com

Suppose you are using a Win32 ListView control in report mode, and you've got all your columns set up perfectly, and you don't want the user to resize them. How do you do that?

There is no ListView style for preventing column resize, but there is a header control style to prevent sizing: HDS_NOSIZING. This style requires Common Controls version 6, but I'm sure you're all using that version already, right?

auto hdr = ListView_GetHeader(hwndLV);
SetWindowLong(hdr, GWL_STYLE,
              GetWindowLong(hdr, GWL_STYLE) | HDS_NOSIZING);

Whether the columns can be resized is independent of whether the columns can be rearranged, which you specify by setting the LVS_EX_HEADER­DRAG­DROP ListView extended style.

ListView_SetExtendedListViewStyleEx(hwndLV,
                                    LVS_EX_HEADERDRAGDROP,
                                    LVS_EX_HEADERDRAGDROP);

Okay, but what if you're stuck in the dark ages with version 5 of the Common Controls? We'll look at that next time.


Post Updated on February 04, 2026 at 03:00PM
Thanks for reading
from devamazonaws.blogspot.com

Comments

Popular posts from this blog

[MS] Debugger breakpoints are usually implemented by patching the in-memory copy of the code - devamazonaws.blogspot.com

Amazon EKS now enforces upgrade insights checks as part of cluster upgrades - devamazonaws.blogspot.com

[MS] Exciting new T-SQL features: Regex support, Fuzzy string-matching, and bigint support in DATEADD – preview - devamazonaws.blogspot.com