Solved

ListView Sorting - CompareFunction

Posted on 2001-07-26
9
702 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
9 Comments
 
LVL 15

Accepted Solution

by:
NickRepin earned 200 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now