Solved

How to enter items in sorted order in a report list view control.

Posted on 1999-01-10
1
241 Views
Last Modified: 2013-11-20
Hi,

I want to add items with a unique date field in a report list view control. Therefore I have made an "Add" button with a linked message handler. Here I convert the date field
entered in a edit control to a CTime object "Date". I use that object to calculate a unique integer value with the following code:

const CTime refDate( 1980, 1, 1, 0, 0, 0 );
int dateID = ( int ) ( Date - refDate ).GetDays();

When I put this number in the "iItem" member of the LV_ITEM struct the CListCtrl::InsertItem call changes this number to a zero based index, so I can forget my sorting.
Is this a good approch of my problem or do I have to solve it a different way. If someone knows the answer please let me know.

                              Thanks in advance.
0
Comment
Question by:bs161900
1 Comment
 
LVL 8

Accepted Solution

by:
Answers2000 earned 20 total points
ID: 1327453


How to do it.
1. Turn off the built in sorting style for the list
2. Store the days value in the row's ItemData (see SetItemData).  When you insert a row, you can an index of the new row back,  then use SetItemData to set day's
3. Repeat #2 as many times as necessary to add all your new items
4. When insertion is complete, then call SortItems member of CListCtrl, this takes a function pointer as 1 parameter, use function #5 (below)
5. You need to define a static CALLBACK function in your code.  This compares 2 items.  Should return -1 (if one less than other), should return 0 (if both same), +1 (if one greater than other) - kind of like strcmp.  This function gets the item data for the two items you're comparing
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 101
lucky13 challenge 11 147
Way to decrease size of apk file 9 70
Problem to App source 6 40
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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