ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

ListView Control Hangs during Sort

<< < (2/3) > >>

Stoic Joker:
A ListView will hang if the CompareProc returns inconsistent results, eg a < b < c but c < a.

In the code posted there seems to be a logic error in line 20, really seems like it should be return i2-i1;
-Eóin (October 07, 2009, 04:49 PM)
--- End quote ---
Hm... wouldn't that then have to fail consistently for all (numerically sorted) columns? In the program (with the issue) half the columns are sorted numerically and half are sorted alphabetically. Out of the numerically sorted columns there are IP Addresses, (alpha-numeric) serial numbers, and some actual real live plain old numbers ranging from (roughly) -185,456 - 1,456,789 all of which sort just fine ... unless they are in column 14 (13 if you count from 0 - the control does). It just doesn't track that a logic bugg would be that forgiving.

*Shrug*

I'll put that on my todo list and try it in the morning when I get to the office (I'd certainly love a simple answer), but it just doesn't feel right...Perhaps because I'm mentally stuck (or just mental) on the column count bugg.

mouser:
i think Eoin may have nailed it.

Stoic Joker:
i think Eoin may have nailed it.
-mouser (October 07, 2009, 05:37 PM)
--- End quote ---
Sorry No Joy.

I decided to remote into the office & try it (the suspense was killing me...). ...I'll give you this much, the sort is a bit smoother. But it still locks up on column 14.

Just to make sure nothing was being missed, I commented out all of the numeric sort code so everything had to be sorted alphabetically. 1-13 = perfect ... 14 = ListView Control hang/frozen solid. :(

mouser:
nSortDir[7]; <--- only goes up to index 0-6 and yet you are sorting on column 14?

Stoic Joker:
It's an old code sample, the actual project is nSortDir[14];

Strangely (Since I'd been missing that seemingly key point) Id left the original nSortDir[7] in the project while User Requests caused columns to be added and it never caused a problem until adding the last 14th column. I've still got a 13 column version of the program using nSortDir[7] that works just fine (Damn strange in retrospect). That was the first thing I tried when the bugg was discovered.

Just for clarity (Now that I'm logged into the office), here is the most current version of the broken code :):

--- Code: C++ ---#include "stdafx.h" extern HWND g_hListBox; int CALLBACK ListViewCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) {        static char szBuf1[100], szBuf2[100];        extern int nSortDir[14];//[7];        int i1, i2;    //=================================== Retrieve the item text so we can compare it.  ListView_GetItemText(g_hListBox, lParam1, (int)lParamSort, szBuf1, sizeof(szBuf1));  ListView_GetItemText(g_hListBox, lParam2, (int)lParamSort, szBuf2, sizeof(szBuf2));  //============================================= Then Return the Comparison Results.  if((lParamSort == 5)||(lParamSort >= 7)) { // Sort Only PageCount Columns 5 and 7     i1 = strtol(szBuf1, 0, 10);  //-+++--> & up as a Number. Columns 4 & below and         i2 = strtol(szBuf2, 0, 10); //--+++--> 6 are Sorted as Words (alphabetically).     if(nSortDir[lParamSort]) //========= Toggle Between ASCENDING & DESCENDING ORDER            return i1-i2; //====================================== Sort Order ASCENDING         else                     // Thanks Eóin - From DonationCoder.com            return i2-i1;// <--Good/Bad--> i1+i2; //============= Sort Order DESCENDING   }else{ //========================= Sort ALL the Rest (Alphabetically) as a String.         if(nSortDir[lParamSort]) //========= Toggle Between ASCENDING & DESCENDING ORDER                return(_stricmp(szBuf1, szBuf2) * -1); //=============== Sort Order ASCENDING         else                return(_stricmp(szBuf1, szBuf2)); //=================== Sort Order DESCENDING  }} // Check to see if Alpha or Num Sort Locks up more/less/same/* Note: This resolved a tendence to periodically sort things incorrectlyEóin Re: ListView Control Hangs during Sort « Reply #4 on: 10/7/2009 at 04:49:47 PM » ------------------------------------------- A ListView will hang if the CompareProc returns inconsistent results, eg a < b < c but c < a. In the code posted there seems to be a logic error in line 20, really seems like it should be return i2-i1;*/

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version