Link to home
Start Free TrialLog in
Avatar of petasf
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.
Avatar of petasf
petasf

ASKER

Adjusted points to 100
Could you show your custom compare function?
Avatar of petasf

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)lparam1,cs->col,buf1,49);
   cs->lv->GetItemText((int)lparam2,cs->col,buf2,49);

   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.
Avatar of petasf

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::SortItems()
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(const TLwComparator& comparator, uint32 lParam)
{
  TListCompareThunk ct;
  ct.This = &comparator;
  ct.ItemData = lParam;
  return ToBool(SendMessage(LVM_SORTITEMS, TParam1(&ct), TParam2(OwlListViewCompare)));
}


ASKER CERTIFIED SOLUTION
Avatar of snoegler
snoegler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of petasf

ASKER

Thanks Snoegler
Functionality of ListView makes me sometimes crazy.