CListCtrl - stop headers from being resized
-
Hi everybody, For a CListCtrl with the report style, is there an easy way to prevent the user from resizing the column headers? I was hoping there would be a style setting for this, but I can't find it. Thanks a lot. Ren
-
Hi everybody, For a CListCtrl with the report style, is there an easy way to prevent the user from resizing the column headers? I was hoping there would be a style setting for this, but I can't find it. Thanks a lot. Ren
I am not 100% sure about this, but you need to handle the HDN_BEGINDRAG message (?) and return FALSE. I seem to recall this from somewhere. Hope its of help. Roger Allen Sonork 100.10016 WHats brown and sticky? A stick or some smelly stuff!
-
Hi everybody, For a CListCtrl with the report style, is there an easy way to prevent the user from resizing the column headers? I was hoping there would be a style setting for this, but I can't find it. Thanks a lot. Ren
You need to handle the HDN_BEGINTRACK notification sent by the list's header control, and return TRUE to disable resizing. [edit]changed FALSE to TRUE above (whoops!)[/edit]
"We are the knights who say Ni" (The Knights Who Say Ni)
-
Hi everybody, For a CListCtrl with the report style, is there an easy way to prevent the user from resizing the column headers? I was hoping there would be a style setting for this, but I can't find it. Thanks a lot. Ren
If you implement a notification handler for HDN_BEGINTRACK and within that function set *pResult = TRUE, that will prevent the header sizing from happening. Unfortunately, the handler for HDN_DIVIDERDBLCLICK does not allow this override, so header sizing can still happen if the user double clicks a header divider. I don't know a way to change this behavior. Ron Ward
-
If you implement a notification handler for HDN_BEGINTRACK and within that function set *pResult = TRUE, that will prevent the header sizing from happening. Unfortunately, the handler for HDN_DIVIDERDBLCLICK does not allow this override, so header sizing can still happen if the user double clicks a header divider. I don't know a way to change this behavior. Ron Ward
Hi, I tried this, but nothing seems to happen. Resizing is still possible. I just used the classwizard to add a handler for =HDN_BEGINTRACK and made the change you suggested, like this: void CMyList::OnBegintrack(NMHDR* pNMHDR, LRESULT* pResult) { HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR; *pResult = TRUE; } Perhaps there is something else I'm doing that's preventing your solution from working. But I can't find anything out of the ordinary. I just SubClassDlgItem() and set the extended style to include gridlines and fullrowselect. Any ideas? Thanks. Ren.
-
Hi, I tried this, but nothing seems to happen. Resizing is still possible. I just used the classwizard to add a handler for =HDN_BEGINTRACK and made the change you suggested, like this: void CMyList::OnBegintrack(NMHDR* pNMHDR, LRESULT* pResult) { HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR; *pResult = TRUE; } Perhaps there is something else I'm doing that's preventing your solution from working. But I can't find anything out of the ordinary. I just SubClassDlgItem() and set the extended style to include gridlines and fullrowselect. Any ideas? Thanks. Ren.
If you use classwizard to insert a handler for HDN_BEGINTRACK in the list control, it incorrectly inserts a reflection handler, even though the notification is sent directly to the list control (ie not through the reflection mechanism). That's why the classwizard handler is marked =HDN_BEGINTRACK (= indicates a reflected notification). You need to replace the line
ON_NOTIFY_REFLECT(HDN_ENDTRACK, OnEndtrack)
in the message map withON_NOTIFY(HDN_ENDTRACK, 0, OnEndtrack)
. (See the MSDN knowledge base article Q281155)
"We are the knights who say Ni" (The Knights Who Say Ni)
-
If you use classwizard to insert a handler for HDN_BEGINTRACK in the list control, it incorrectly inserts a reflection handler, even though the notification is sent directly to the list control (ie not through the reflection mechanism). That's why the classwizard handler is marked =HDN_BEGINTRACK (= indicates a reflected notification). You need to replace the line
ON_NOTIFY_REFLECT(HDN_ENDTRACK, OnEndtrack)
in the message map withON_NOTIFY(HDN_ENDTRACK, 0, OnEndtrack)
. (See the MSDN knowledge base article Q281155)
"We are the knights who say Ni" (The Knights Who Say Ni)
Sorry guys, but it's still not working. I've tried changing the message map as directed, but nothing happens. The message is still not sent. (I've checked with a messagebox.) I noticed that the MSDN article refers to CListView while I'm working with a CListCtrl. Could this have anything to do with it?
-
Sorry guys, but it's still not working. I've tried changing the message map as directed, but nothing happens. The message is still not sent. (I've checked with a messagebox.) I noticed that the MSDN article refers to CListView while I'm working with a CListCtrl. Could this have anything to do with it?
I had gone through this in a lengthy thread a while back on CodeGuru: http://www.codeguru.com/forum/showthread.php?s=&threadid=215009[^] There are several ways to handle it. Chris Richardson C/C++ Include Finder[^]
-
I had gone through this in a lengthy thread a while back on CodeGuru: http://www.codeguru.com/forum/showthread.php?s=&threadid=215009[^] There are several ways to handle it. Chris Richardson C/C++ Include Finder[^]
I have to admit I don't really understand everything being explained in the thread, but no worries: it works now. I'll just give a short report for any interested parties too lazy to check the thread you mentioned: PROBLEM: Stop CListCtrl column headers from being resized. SOLUTION: Let your view handle the HDN_BEGINTRACK message and have it return TRUE.
void CMyList::OnBegintrack(NMHDR* pNMHDR, LRESULT* pResult) { HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR; *pResult = TRUE; }
BUG: Something about the class wizard messing up and another thing about unicode and ansi, which results in your handler never being called. FIX: Edit your message map manually. First remove:ON_NOTIFY_REFLECT(HDN_BEGINTRACK,OnBeginTrack)
And instead add:ON_NOTIFY(HDN_BEGINTRACKW, 0, OnBegintrack) ON_NOTIFY(HDN_BEGINTRACKA, 0, OnBegintrack)
That's it. Thanks 4 the help, guys.