Thread: Listview arrow in column head

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    2

    Listview arrow in column head

    Hi guys,

    this is a minor question but I just don't find the answer on MSDN or google.

    How do I activate the small arrow (for sorting) in the head of the column in a
    listview? I am using plain C, no MFC etc. (Mingw + gcc).

    Thanks

    Thomas

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    76
    I looked for exact the same thing a while ago. I found an aswer, but it was so much trouble to implement, i didnt add it. Unfortunately i dont remember where i found the answer.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Welcome to the forums!

    I whipped up a little function. Enjoy.
    Code:
    typedef enum 
    {
       SHOW_NO_ARROW,
       SHOW_UP_ARROW,
       SHOW_DOWN_ARROW
    } SHOW_ARROW;
    
    /*
     * Description: Given a list-view control, this function will set the
     *              sort arrow for a specific column.
     * Requirements: ComCtl32.dll Version 6 (available on XP and greater).
     *               To use Comctl32.dll version 6, you must specify it in a manifest.
     *               You also need to add: #define _WIN32_WINNT 0x501
     *               before including commctrl.h
     * Example: xListViewSetSortArrow(hListView, 0, SHOW_UP_ARROW);
     */
    BOOL xListViewSetSortArrow(HWND hListView, INT idxColumn, SHOW_ARROW showArrow)
    {
    	HWND    hHeader  = NULL;
    	HDITEM  hdrItem  = { 0 };
    
    	hHeader = ListView_GetHeader(hListView);
    
    	if (hHeader)
    	{
    		hdrItem.mask = HDI_FORMAT;
    
    		if ( Header_GetItem(hHeader, idxColumn, &hdrItem) )
    		{
    			if (showArrow == SHOW_UP_ARROW)
    			{
    				hdrItem.fmt = (hdrItem.fmt & ~HDF_SORTDOWN) | HDF_SORTUP;
    			}
    			else if (showArrow == SHOW_DOWN_ARROW)
    			{
    				hdrItem.fmt = (hdrItem.fmt & ~HDF_SORTUP) | HDF_SORTDOWN;
    			}
    			else 
    			{
    				hdrItem.fmt = hdrItem.fmt & ~(HDF_SORTDOWN | HDF_SORTUP);
    			}
    
    			return Header_SetItem(hHeader, idxColumn, &hdrItem);
    		}
    	}
    
    	return FALSE;
    }
    I think this may be possible for platforms prior to XP, but it is more complex and you would have to supply your own arrow images. There is a generic list-view sample that this function could be used with.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    2
    Thanks, I think that will help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vertical column in ListView
    By underline_bruce in forum Windows Programming
    Replies: 6
    Last Post: 11-15-2008, 09:35 AM
  2. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  3. Retrieving Multiple inputs with fgets?
    By Axel in forum C Programming
    Replies: 25
    Last Post: 09-13-2005, 04:04 PM
  4. Can't figure out problem with code
    By Beast() in forum C Programming
    Replies: 4
    Last Post: 04-16-2005, 05:27 PM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM