?
Solved

ListView Sorting - CompareFunction

Posted on 2001-07-26
9
Medium Priority
?
715 Views
Last Modified: 2013-12-03
Hi...
I would liekt to sor the listview according to column which was pressed.
Everything is OK until the
CompareFun(LPARAM lParam1,LPARAM lParam2,LPARAM sortParm)
is hit. Neither of the LPARAM 1 or 2 pass what they suposed to. They pass a value of 0 for both and sortParam
passes the column which was pressed. Below is my source.

ItemStruct *pItem1    = (ItemStruct*) lParam1;
ItemStruct *pItem2    = (ItemStruct*) lParam2;
After this assignment is done both of these are NULL
ie: pItem1 , pItem2.

Can someone take a look and tell me what is wrong.

Thank you in Advance.
Kind Regards Paul
---------------------------------------------------------
typedef struct
{
  int nItemNo;
  char strName[110];
}ItemStruct;

int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
  int result;
  ItemStruct *pItem1    = (ItemStruct*) lParam1;
  ItemStruct *pItem2    = (ItemStruct*) lParam2;
  if(pItem1 ==  NULL || pItem2 == NULL)
     return 0;
  switch(lParamSort)
  {
    case 0:
      if(pItem1->nItemNo < pItem2->nItemNo)
         result = -1;
      else
      if(pItem1->nItemNo == pItem2->nItemNo)
         result = 0;
      else
         result = 1;
      break;

      case 1:
        result = strcmp(pItem1->strName,pItem2->strName);
        break;

      default:
        result = 0;
        break;
  }
  return result;
}

void OnColumnclickList1(HWND hWnd,LPARAM lParam)
{
    HWND lWnd;
    int nColumn;
    NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)lParam;
     lWnd = GetDlgItem(hWnd,ID_SEARCHLIST);
    nColumn = pNMListView->iSubItem;
    ListView_SortItems(lWnd,CompareFunc,nColumn);
}

LRESULT SListViewNotify(HWND hWnd,LPARAM lParam)
{
   LPNMHDR  lpnmh = (LPNMHDR) lParam;
   if(search_set == 0)
      return 0;
   switch(lpnmh->code)
   {
      case LVN_COLUMNCLICK:
         OnColumnclickList1(hWnd,lParam);
         break;
   }
   return 0;
}

---------------------------------------------------------
0
Comment
Question by:pawel3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 15

Accepted Solution

by:
NickRepin earned 800 total points
ID: 6324782
<<The lParam1 parameter is the 32-bit value associated with the first item being compared, and the lParam2 parameter is the value associated with the second item.>>

You have to explicitely assign a certain value to lParam for each listview item when you create a listview.

By default, lParam contains zero.

lParam is among other members in LVITEM structure.

0
 
LVL 5

Expert Comment

by:robpitt
ID: 6324802
Question:
In your OnColumnclickList1() what is the ID_SEARCHLIST thing all about?


Also be sure to check that your actually setting the lParam correctly in the first place. I.e. check that the LVITEM mask member includes LVIF_PARAM as well as setting the lParam member to your structure address.

Rob
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6326006
PS Ignore my first question about ID_SEARCHLIST - I was just being dim.
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

Expert Comment

by:AKRover
ID: 6372658
can u post the code that uses LVM_INSERTITEM?
0
 

Author Comment

by:pawel3
ID: 6681287
thank you NickRepin
you suggestion worked fine
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 6682531
if so then could you accept my comment as an answer?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question