Solved

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

Posted on 2007-11-29
3
292 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

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
Problem to adjust sheet 1 85
Copying WordPress Pages 5 76
withoutTen challenge 14 97
Need to impress with my knowledge of .NET 5 81
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

947 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