Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone!

I have small question.

I was looking for solution to change sort arrows of header in CMFCListCtrl. And I found only
post on msdn
C++
CMFCHeaderCtrl::OnDrawSortArrow
and nothing more. But I don't know how to use it.
And actually I have icon for this arrows.

Thank you
Posted

1 solution

I think you can do it using normal SetItem method.

Provided you have an CImageList member variable called m_imgOrder in your class populate it with your icons. Image 0 will be your ascending icon and Image 1 will be a descending one.
C++
// hIconAsc and hIconDes are the HICON values for Ascending and Descending icons
// Set it once
m_imgOrder.Create(16, 16, ILC_MASK, 2, 2);
m_imgOrder.Add(hIconAsc);
m_imgOrder.Add(hIconDes);
GetHeaderCtrl()->SetImageList(&m_imgOrder);


This function will draw your own icons from the Image list you have created:
C++
void CMyListCtrl::DisplayHeaderOrder(int nIndex, BOOL bAsc)
{
  HD_ITEM curItem = {0};
  curItem.mask    = HDI_IMAGE | HDI_FORMAT;
  GetHeaderCtrl()->GetItem(nIndex, &curItem);
  curItem.mask    = HDI_IMAGE | HDI_FORMAT;
  curItem.iImage  = bAsc ? 0 : 1;
  curItem.fmt     = HDF_LEFT | HDF_IMAGE | HDF_STRING|HDF_BITMAP_ON_RIGHT;
  GetHeaderCtrl()->SetItem(nIndex, &curItem);
}
 
Share this answer
 
Comments
thomas_wingfield 30-Oct-13 8:08am    
Thanks Andrew for posting
but I get image only to left side despite HDF_BITMAP_ON_RIGHT. I can't set it where exist default arrow
I did it like your example for CListCtrl a couple days ago, but for CMFCListCtrl it works only for left side(
chaau 30-Oct-13 15:00pm    
Try to use CListCtrl. See if it is better.
thomas_wingfield 31-Oct-13 6:04am    
I have to use CMFCListCtrl!
Actually I found solution to create CMFCHeaderCtrl and Attach it to CMFCListCTrl and override OnDrawArrows
Thanks that you posted it! I tried your solution but this works fine for only CListCtrl
Hope my answer will help somebody in future

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