Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
dog bark java program 15 82
EvenOdd challenge 10 83
scoreUp challenge 14 48
Post a good COM tutorial 1 34
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

759 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

19 Experts available now in Live!

Get 1:1 Help Now