Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

How can I turn off CListCtrl sorting??

I derived CListCtrl and CHeaderCtrl, in PreSubclassWindow() of new list control class i did something like following to disable list sorting.

C
if(GetHeaderCtrl())
{
   m_headerCtrl.SubclassWindow(GetHeaderCtrl()->m_hWnd);
   m_headerCtrl.ModifyStyle(HDS_BUTTONS, 0);
}


I did set sort property of list control in resource file to "None" and view type to "Report". But when I insert item into list using LV_ITEM struct in my specific order, items are re-sorted.

Did i miss something here in order to disable list control's sorting?
Posted

I am not sure but may be the following code will help: -

C#
CHeaderCtrl* pHeader = GetListCtrl().GetHeaderCtrl();
if( pHeader!=NULL)
{
            pHeader->ModifyStyle(HDS_BUTTONS, 0);    // disable the sorting.
}



Hope this helps. Let me know if it worked

--
AJ
 
Share this answer
 
Comments
quyps 11-May-11 0:05am    
Thanks, i place those lines in OnInitDialog() of the list control's container, but it doesnt work. The list's items are still sorted in descending order.
ankitjoshi24 11-May-11 10:16am    
Did you keep the default sorting of the list as descending? Try doing one thing, try to enter a random data. And then check if the list is gets sorts again or is the new data somewhere either at the start of at the end.
I figured it out. In my OnInitDialog() function, i have

DWORD dwStyle = m_lstCtrl.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT;
m_lstCtrl.ModifyStyle(0, dwStyle | LVS_REPORT);


By commenting out these lines and applying ankitjoshi24's solution,the problem is solved.

But still I dont understand why these lines caused the problem??

Quy
 
Share this answer
 
Comments
Rajesh R Subramanian 27-Mar-17 23:47pm    
This was caused because LVS_REPORT causes a column header to be introduced, which is usually clicked for sorting the corresponding column. Removing that style removed the column header, and the associated (perhaps default?) sorting.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900