?
Solved

List control sort problem

Posted on 2001-08-29
9
Medium Priority
?
796 Views
Last Modified: 2013-11-20
When using a List control in a dialog based application I (with just a little C++ experience:) ran into something strange. The implementation should be straightforward and pretty simple and it was except for one thing.

When I sort the items in descending order by setting the descending property of the List control the last item overwrites the first one (displaying only 4 out of 5 items) when using the small icon view. When I sort the items in ascending order all items are sorted and displayed as they should.
If I set the list view instead of the small icon view descending as well as ascending sort work well.

What's wrong?

here's the code:
I added a CImageList data member "m_imageList" to the Dialog class and created an image list in the constructor "m_imageList.Create(16,16,0,10,5);"

The list control's initialization in the OnInitDialog() memberfunction looks like this:

HICON hIcon;
hIcon=AfxGetApp()->LoadIcon(IDI_ICON1);
CListCtrl* pList=(CListCtrl*)GetDlgItem(IDC_LIST1);
pList->SetImageList(&m_imageList,LVSIL_SMALL);

static char* s[]={"axx","bxx","cxx","dxx","exx"};
     
for (int i(0); i<5; i++)
{
     m_imageList.Add(hIcon);
     pList->InsertItem(i,s[i],i);
}

--------------
So, descending sort displays axx,dxx,cxx,bxx and ascending sort displays axx,bxx,cxx,dxx,exx.
0
Comment
Question by:schuurbiers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 6436428
hmm, that's strange, for I tested it on my m/c and it works as expected...

what OS and VC do you use?
0
 

Author Comment

by:schuurbiers
ID: 6436481
Win98 and VC6.0
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 6436745
Well, I can't help you since I can't reproduce this (Win2k with VC 6.0) ... even
can't find anything about such problem in MSDN. Sorry...
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 

Author Comment

by:schuurbiers
ID: 6439471
It's a weird thing I agry .....
Thanks for trying anyway!

btw is there a way to arrange the "list" view in just one column? I use the "small icon" view only because this view displays the items in just one column with a vertical scoll bar wich is what I want.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 6439544
Hmm, I don't understand exactly what you mean with the last question, but
another way then using 'small icon' would be to use 'report' with one column
and without header.

But, I think maybe I found solution to you problem: As I'm used to create columns
for listcontrols (coz I usually use 'report' list controls) I did this without taking care
that in your code it isn't done. Now, at least for 'small icons' list control I saw on
my machine that sorting is incorrect if I don't create a column (I get correct number
of items but first is 'axx' instead of 'exx') ... when I do add a column it sorts correct, i.e.:

HICON hIcon;
hIcon=AfxGetApp()->LoadIcon(IDI_ICON1);
CListCtrl* pList=(CListCtrl*)GetDlgItem(IDC_LIST1);
m_imageList.Create(16,16,0,10,5);
pList->SetImageList(&m_imageList,LVSIL_SMALL);
pList->InsertColumn( 0, "Test" ); // addin this makes sorting work correct for 'small icons'
static char* s[]={"axx","bxx","cxx","dxx","exx" };

for (int i(0); i<5; i++)
{
 m_imageList.Add(hIcon);
 pList->InsertItem(i,s[i],i);
}

// this is only used if you want to use 'report' lit control to adjust columns width depending
// on need of scrollbar
CRect rect;
pList->GetClientRect( rect );
pList->SetColumnWidth( 0, rect.Width() );    


I hope this helps,

ZOPPO
0
 

Author Comment

by:schuurbiers
ID: 6439582
Hi Zoppo!

>Hmm, I don't understand exactly what you mean with the last question,

Well, the "list" view of a List control arranges the items in multiple columns and a horizontal scroll bar while the "small icon" view arranges the items in one column and a vertical scroll bar which is what I want.

But I'm glad you could reproduce the same sort error I ran into. And inserting a column to the List control (but why should you if it's already there?) indeed solved the sort error.
Thanks!

Btw isn't this a bug in the CListctrl class?
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 400 total points
ID: 6439745
So, then I understood it correctly ... I think you can use even 'report' list with one column and w/o header.

>Btw isn't this a bug in the CListctrl class?
hmm, with MS-products it's often hard to differentiate between bug and feature    :)
0
 

Author Comment

by:schuurbiers
ID: 6439779
guess you're right about that last comment :)
thanks again ...
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 6439790
you're welcome,

have a nice day,

regards,

ZOPPO
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question