Thread: sorting list view items

  1. #1
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62

    sorting list view items

    i cant figure out how to sort the items in my list view control. When i press teh column header the items go in the wrong order.

    here is my code:

    Code:
    int CALLBACK SortListFunc(LPARAM i1, LPARAM i2, LPARAM lParam)
    {
    	NMLISTVIEW *pnmlv = (NMLISTVIEW*)lParam;
    
    	char str2[200];
    	ListView_GetItemText(pnmlv->hdr.hwndFrom, i1, pnmlv->iSubItem, str, 200);
        ListView_GetItemText(pnmlv->hdr.hwndFrom, i2, pnmlv->iSubItem, str2, 200);
    	
    	return strcmp(str2, str);
    }
    
    case LVN_COLUMNCLICK:
    				{
    					NMLISTVIEW *pnmlv = (NMLISTVIEW*)lParam;
    					
    					ListView_SortItems(pnmlv->hdr.hwndFrom, SortListFunc, lParam);
    					
    					break;
    				}
    and when i am adding an item:
    Code:
    int i = ListView_GetItemCount(list);
    
    	LVITEM lvi = {0};
    	lvi.mask = LVIF_TEXT | LVIF_PARAM;
    	lvi.iItem = i;
    lvi.lParam = i;
    
    ListView_InsertItem(taglist, &lvi);
    any ideas?
    Last edited by cppdude; 06-06-2002 at 06:39 PM.

  2. #2
    Unregistered
    Guest
    Hard to read the code as posted.

    Are you disabling the msg's to the listview while sorting?

  3. #3
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62
    umm no why?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help sorting a linked list. Beginner
    By scarlet00014 in forum C Programming
    Replies: 1
    Last Post: 09-27-2008, 06:16 PM
  2. List View troubles (adding items)
    By scwizzo in forum Windows Programming
    Replies: 5
    Last Post: 09-08-2008, 04:09 PM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. preventing editing of List View item's label
    By larry in forum Windows Programming
    Replies: 7
    Last Post: 02-24-2003, 08:25 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM