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
Solved

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

Posted on 2007-11-29
3
295 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
how to split multiple lines delimiter : 8 109
The line on IDE 4 91
windbg taking it's time 32 93
C# LINQ ForEach() question 6 54
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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 synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

860 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