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

(1/3) > >>

Stoic Joker:
Greetings
   I seem to recall seeing the answer for this once before, I just can't remember where... *Sigh*

   Anyhow, I have an app I'm working on (suite of them actually) that display's data which is queried from a MySQL db. It's written (as usual for me) in straight Win32 API C++ (No .Net/MFC/etc.). The issue I'm having is that when the list box control is sorted by the (14th) Cost column the ListView control locks up untill the app is restarted.

   Now in the various columns I do switch between alphabetical & numeric sorting, which works just fine for the first 11 columns, but... 12 & 13 only sort one direction instead of toggling between asc & desc, and 14 just hangs the LV thread completely. I've been using the same ListView Sort code in several different apps that all work just fine, but have 10 colums or less.

   Which brings me to (the point?) my question. Does anybody recall seeing an issue with (and solution for) ListView controls having more than X number of columns hanging during sort? I swear I've seen this before reguarding a bugg in the LV control ... I just can't remember where or what the solution was.

I'm using MSVS 2005 SP1

Thank You

mouser:
how many rows of data?

f0dder:
Never heard of such a bug (but not saying it can't exist :)).

How do you manage the items? virtual mode, or letting the control manage strings internally?

Stoic Joker:
how many rows of data?
-mouser (October 07, 2009, 03:33 PM)
--- End quote ---
Doesn't matter be it 3 or 300 (Most I ever tried was 2000) behavior is the same.

Never heard of such a bug (but not saying it can't exist :)).

How do you manage the items? virtual mode, or letting the control manage strings internally?
-f0dder (October 07, 2009, 03:43 PM)
--- End quote ---
If I'm understanding the question correctly, the control is managing internally. I'm not doing anything OwnerDrawn/Clever it's just a fairly straight forward ListView_InsertColumn(...) ListView_InsertItem(...) sort of affair.

This is basically the sort code I'm using (from an older 7 column version of the app):

--- Code: C++ ---#include "stdafx.h" extern HWND g_hListBox;extern int nSortDir[7]; int CALLBACK ListViewCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) {        static char szBuf1[100], szBuf2[100];        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) { //================= Sort PageCount Columns 5 & 6 as a Number.     i1 = strtol(szBuf1, 0, 10);         i2 = strtol(szBuf2, 0, 10);     if(nSortDir[lParamSort]) //========= Toggle Between ASCENDING & DESCENDING ORDER            return i1-i2; //====================================== Sort Order ASCENDING         else            return 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  }}
It was probably 2 years ago when I saw the bugg discussion ... thinking that I'd never need to use that many columns I ignored it and moved on to other more (at the time) relevant issues. Now I'm racking my brain trying to remember where I'd seen it because (several columns later) the bugg is now gnawing my ass off :)

Eóin:
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

Go to full version