Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 1999-01-10
1
Medium Priority
?
252 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 60 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

824 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