Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SAPE.heur.AE935 Visual Studio 3 61
wordappend challenge 8 221
eclipse formatting 6 114
Interview questions for support of a legacy ASP.NET site 4 71
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

685 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