Solved

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

Posted on 1999-01-10
1
239 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 56
only14 challenge 19 68
Use of condition with 'serial' in ansible 2 49
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 242
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now