pawel3
asked on
ListView Sorting - CompareFunction
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,pIt em2->strNa me);
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_SEARCHL IST);
nColumn = pNMListView->iSubItem;
ListView_SortItems(lWnd,Co mpareFunc, 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,lP aram);
break;
}
return 0;
}
-------------------------- ---------- ---------- ---------- -
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,pIt
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_SEARCHL
nColumn = pNMListView->iSubItem;
ListView_SortItems(lWnd,Co
}
LRESULT SListViewNotify(HWND hWnd,LPARAM lParam)
{
LPNMHDR lpnmh = (LPNMHDR) lParam;
if(search_set == 0)
return 0;
switch(lpnmh->code)
{
case LVN_COLUMNCLICK:
OnColumnclickList1(hWnd,lP
break;
}
return 0;
}
--------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PS Ignore my first question about ID_SEARCHLIST - I was just being dim.
can u post the code that uses LVM_INSERTITEM?
ASKER
thank you NickRepin
you suggestion worked fine
you suggestion worked fine
if so then could you accept my comment as an answer?
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