We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Sorting in OWL implementation of ListView

petasf
petasf asked
on
Medium Priority
403 Views
Last Modified: 2008-02-01
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.
Comment
Watch Question

Author

Commented:
Adjusted points to 100

Commented:
Could you show your custom compare function?

Author

Commented:
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);
}

Commented:
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.

Author

Commented:
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)));
}


Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Thanks Snoegler
Functionality of ListView makes me sometimes crazy.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.