Solved

MFC, C++: Associating a value with a report-style CListCtrl row, to resolve later database queries.

Posted on 2007-11-29
3
294 Views
Last Modified: 2013-12-14
Hello,

I am writing an application, a database front-end, that makes heavy use of report-style CListCtrls . I would like to be able to associate a Primary key value (essentially, an integer) with a row of some of those CListCtrls, so that when the user requests more information on the record that relates to the row, I can retrieve the row's "hidden value", the primary key value,  without displaying it, which is what I've been doing up until now. This is no longer appropriate.

So, how could I associated a "hidden value" with a row? It seems pretty likely that such a facility exists, for this very reason,
Thanks,
Sternocera
0
Comment
Question by:sternocera
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
alb66 earned 500 total points
ID: 20372697
You can use CListCtrl::SetItemData():

// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;

// Set the data of each item to be equal to its index.
for (int i=0;i < pmyListCtrl->GetItemCount();i++)
{
   pmyListCtrl->SetItemData(i, i);
}
0
 
LVL 19

Expert Comment

by:alb66
ID: 20372703
Use GetItemData() to retrive the previously saved data:

// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;

// If any item's data is equal to zero then reset it to -1.
for (int i=0;i < pmyListCtrl->GetItemCount();i++)
{
   if (pmyListCtrl->GetItemData(i) == 0)
   {
      pmyListCtrl->SetItemData(i, (DWORD) -1);
   }
}
0
 

Author Comment

by:sternocera
ID: 20372733
Great,thanks.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
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.

832 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