petasf
asked on
Sorting in OWL implementation of ListView
Hi
I've a problem with sorting in OWL TListView. I've written my custom compare function. When I'm calling ListView->SortItems function for the first time, everything is OK. Items are sorted correctly. Buf the second call of SortItems func. gives items back to the state after initialization (same order as it was after adding in SetupWindow()). What's wrong ?
I'm using Borland BC5.02 compiler under WIN NT 4.0 Workstation.
I've a problem with sorting in OWL TListView. I've written my custom compare function. When I'm calling ListView->SortItems function for the first time, everything is OK. Items are sorted correctly. Buf the second call of SortItems func. gives items back to the state after initialization (same order as it was after adding in SetupWindow()). What's wrong ?
I'm using Borland BC5.02 compiler under WIN NT 4.0 Workstation.
Could you show your custom compare function?
ASKER
int CALLBACK CompareProc(LPARAM lparam1, LPARAM lparam2, LPARAM lparamSort)
{
int result;
char buf1[50];
char buf2[50];
CmpStruct *cs = (CmpStruct*)lparamSort;
cs->lv->GetItemText((int)l param1,cs- >col,buf1, 49);
cs->lv->GetItemText((int)l param2,cs- >col,buf2, 49);
result = lstrcmpi(buf1,buf2);
return(result);
}
{
int result;
char buf1[50];
char buf2[50];
CmpStruct *cs = (CmpStruct*)lparamSort;
cs->lv->GetItemText((int)l
cs->lv->GetItemText((int)l
result = lstrcmpi(buf1,buf2);
return(result);
}
I don't know the OWL very well but i would guess that it could help to reset the contents first
and call the SortItems() function after that.
Perhaps the SortItems() function sort relatively - so that the first call sorts the items, the next
call reverses the sort again, and so on ... (just guessing)
Do you have the source code of this SortItems() function - if yes, you could post it here to
let us take a look on it.
and call the SortItems() function after that.
Perhaps the SortItems() function sort relatively - so that the first call sorts the items, the next
call reverses the sort again, and so on ... (just guessing)
Do you have the source code of this SortItems() function - if yes, you could post it here to
let us take a look on it.
ASKER
Yes it looks like you've said. - the naxt call the SortItems() really reverses order of items. But in my opinion it should work this way. The first call sorts items for example in the ascent order (it depends on your custom compare function, of course), the next call reverses sort, so after sort, items are in descent order. But it doesn't work like this.The next call of SortItems() gives items back to the state after initialization -my items are not sorted after initialization.
Here is source code of OWL::TListWindow::SortItem s()
BUT I'M USING THE CALL OF THE WIN32 MACRO ListView_SortItems
BOOL ListView_SortItems(
HWND hwnd,
PFNLVCOMPARE pfnCompare,
LPARAM lParamSort
);
//
// Sort the items within the List Window.
// TLwComparator is the base class for the comparison function
//
bool TListWindow::SortItems(con st TLwComparator& comparator, uint32 lParam)
{
TListCompareThunk ct;
ct.This = &comparator;
ct.ItemData = lParam;
return ToBool(SendMessage(LVM_SOR TITEMS, TParam1(&ct), TParam2(OwlListViewCompare )));
}
Here is source code of OWL::TListWindow::SortItem
BUT I'M USING THE CALL OF THE WIN32 MACRO ListView_SortItems
BOOL ListView_SortItems(
HWND hwnd,
PFNLVCOMPARE pfnCompare,
LPARAM lParamSort
);
//
// Sort the items within the List Window.
// TLwComparator is the base class for the comparison function
//
bool TListWindow::SortItems(con
{
TListCompareThunk ct;
ct.This = &comparator;
ct.ItemData = lParam;
return ToBool(SendMessage(LVM_SOR
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Snoegler
Functionality of ListView makes me sometimes crazy.
Functionality of ListView makes me sometimes crazy.
ASKER