iterating items
Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=4080
Printed Date: 21 November 2024 at 4:34pm Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com
Topic: iterating items
Posted By: adico
Subject: iterating items
Date Posted: 28 April 2006 at 12:04am
i am looking for a good example (vc++) on how to iterate through every single item(column) on a record (row).
i can get the row, but i want to scan every item & find out which item is empty (" ").
Thanx in advance
------------- I am not my memories...I am my dreams!
|
Replies:
Posted By: sserge
Date Posted: 28 April 2006 at 3:47pm
Hi,
If you have a record pointer, you can iterate it in a very simple manner:
CXTPReportRecordItem* pItem = NULL; for (int i = 0; i < pRecord->GetItemCount(); i++) { pItem = pRecord->GetItem(i); if (pItem) { ASSERT(pItem->GetCaption(NULL).IsEmpty()); } }
|
-- WBR, Serge
|
Posted By: adico
Date Posted: 01 May 2006 at 11:03am
Sserge, thanx for your reply. However it doesn't seem to do what I want. Here is the code:
CXTPReportRecordItem* pItem = NULL;
CXTPReportRecord* pRecord = (CXTPReportRecord*)m_wndReport.GetRecords();
int nItemCnt = pRecord->GetItemCount();
for(int i = 0; i < nItemCnt; i++)
{
pItem = pRecord->GetItem(i);
if(pItem) // IT NEVER GETS INSIDE HERE
{
ASSERT(pItem->GetCaption(NULL).IsEmpty());
}
}
it never gets inside the if(pItem) statement.
am i missing something?
Basically this is what I want to do: when the user clicks on a button,
i want to get a total count of all the rows in the report. then
starting with the first row, i want to iterate thru all the items &
find out if there are any empty items. if so, i want to break out of
the look & set focus (maybe change the cell color) to the first
empty item.
------------- I am not my memories...I am my dreams!
|
Posted By: sserge
Date Posted: 01 May 2006 at 5:29pm
Your code above has an error. GetRecords() returns a collection of records, not just a single one. So far, to iterate all records and then items it would be:
CXTPReportRecords* pRecords = wndReport.GetRecords(); CXTPReportRecord* pRecord = NULL;
int nRecordCnt = pRecords->GetCount(); for(int i = 0; i < nRecordCnt; i++) { pRecord = pRecords->GetAt(i); // there goes my previous piece of code CXTPReportRecordItem* pItem = NULL; for (int j = 0; j < pRecord->GetItemCount(); j++) { pItem = pRecord->GetItem(j); if (pItem) { ASSERT(pItem->GetCaption(NULL).IsEmpty()); } } }
|
ps: by your description, you probably need to iterate ReportRows, and only then take and check a Record from a Row.
-- WBR, Serge
|
Posted By: adico
Date Posted: 01 May 2006 at 7:36pm
thanx sserge,
this does what i want (after some minor modifications).
could you elaborate (maybe provide an example) on what you mean by iterating ReportRows?
thnx
------------- I am not my memories...I am my dreams!
|
Posted By: sserge
Date Posted: 02 May 2006 at 5:21am
No problem, firstly look at help files to see the difference between Record and a Row.
Iterating difference is in their order. If you iterate Records, you'll take them in the order like you were adding them into the control. If you iterate Rows, they go in order like they're displayed.
Here is the example (add there NULL checks, etc):
CXTPReportRows* pRows = wndReport.GetRows(); for(int j = 0; j < pRows->GetCount(); j++) { CXTPReportRow* pRow = pRows->GetAt(j); CXTPReportRecord* pRecord = pRow->GetRecord(); for (int i = 0; i < pRecord->GetItemCount(); i++) { CXTPReportRecordItem* pItem = pRecord->GetItem(i); if (pItem) { ASSERT(pItem->GetCaption(NULL).IsEmpty()); } } }
|
-- WBR, Serge
|
|