Solved

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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‚Ķ
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

744 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

14 Experts available now in Live!

Get 1:1 Help Now