Solved

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

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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

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…
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 …
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

632 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