Print Page | Close Window

SetVirtualMode

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=4513
Printed Date: 21 November 2024 at 10:57pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: SetVirtualMode
Posted By: freediver211
Subject: SetVirtualMode
Date Posted: 29 June 2006 at 9:14am
I am trying to add a lot of records to a CXTPReportControl at runtime.  I am using SetVirtualMode to add those records.  However, only the last record is display multiple times.  What am I doing wrong?
 
Inside my method I call:
 
Begin Loop...
rowCount++;
m_wndReportCtrl.SetVirtualMode(new CVirtualMessageRecord  (alarmType,
 deviceId,
 deviceName,
 latitude,
 longitude,
 altitude,
 newEvent), rowCount ); 
End Loop...

m_wndReportCtrl.Populate();

Any thoughts?

Thanks!



Replies:
Posted By: sserge
Date Posted: 29 June 2006 at 10:47am
Hi,

Please look at our VirtualList sample firstly.

Note that in virtual mode there are no a collection of records, but only 1 "virtual" record. All actual data is set on callback with GetItemMetrics method.

--
WBR,
Serge


Posted By: freediver211
Date Posted: 29 June 2006 at 1:01pm
Ok, so how do you pass your data into the callback to populate the list?
 
 


Posted By: sserge
Date Posted: 29 June 2006 at 5:56pm
As you can see from the sample, the key class is CVirtualRecord and key method is GetItemMetrics, which is called before displaying each record item. In your code you can set it's properties including caption, as folllows:
pItemMetrics->strText = "your text". In the sample below it is formatted depneding on the current column and row numbers:

class CVirtualRecord : public CXTPReportRecord
{
public:
    CVirtualRecord()
    {
        AddItem(new CXTPReportRecordItem());
        AddItem(new CXTPReportRecordItem());
        AddItem(new CXTPReportRecordItem());
    }

    void GetItemMetrics (XTP_REPORTRECORDITEM_DRAWARGS* pDrawArgs, XTP_REPORTRECORDITEM_METRICS* pItemMetrics)
    {
        CXTPReportColumnOrder* pSortOrder = pDrawArgs->pControl->GetColumns()->GetSortOrder();

        BOOL bDecreasing = pSortOrder->GetCount() > 0 && pSortOrder->GetAt(0)->IsSortedDecreasing();

        CString strColumn = pDrawArgs->pColumn->GetCaption();
        int nIndex = pDrawArgs->pRow->GetIndex();

        int nCount = pDrawArgs->pControl->GetRows()->GetCount();
        pItemMetrics->strText.Format(_T("%s - Row %i"), strColumn, bDecreasing? nCount - nIndex: nIndex + 1);

    }
};



--
WBR,
Serge


Posted By: freediver211
Date Posted: 30 June 2006 at 9:18am
Serge,
 
I don't think you are understanding my question.  Let me try to explain again with an example.
 
Let's take an example of a database that is being populated at runtime by another process.  Let's say you have x number of new records you want to read from the database and populate via the report control.  If we take your example, we would have to make x number of read seeks to the database for each call back.  Rather, the prefered method would be to get one read from the DB with all the records.  Then for each call back populate the appropriate row.
 
One way to do this is to assign a local variable to the VirtualRecord class which will contain the data (ie. an CList or something).   Then for each call back access the appropriate record.  This doesn't seem the optimal solution. 
 
void GetDataMethod()
{
Begin Loop...
 
pVirtualRecord->SetList(somedata);
 
End Loop...
}
 
 
void GetItemMetrics (XTP_REPORTRECORDITEM_DRAWARGS* pDrawArgs,               XTP_REPORTRECORDITEM_METRICS* pItemMetrics)
    {
         int nIndex = pDrawArgs->pRow->GetIndex();

         CString myData = GetListItem(nIndex);
         pItemMetrics->strText.Format(_T("%s"), myData...);

    }

 
So, can you please explain to me if there is an alternative solution to getting access to the correct data at run time?  
 
 


Posted By: freediver211
Date Posted: 30 June 2006 at 11:45am
Another issue which your demo or documentation does not address is not knowing the record size until run time.
 
If we are adding rows at runtime how then can you dynamically change the row count for a single Virtual Record?
 
Let's say we create a Singleton to the VirtualRecord and we modify the row count, well that doesn't work so I fail to see how virtual mode will work with dynamic data at runtime.
 
 
For example,
 
OnInitDialog() I have let's say 5 records.  Then once the app is loaded I get a sixth record.  How do I dynamically change the row count from 5 to 6?
 


Posted By: sserge
Date Posted: 03 July 2006 at 3:48am
Ok, the answer firstly. This piece of code could be used to change row count:

wndReport.SetVirtualMode(new CVirtualRecord(), 6);
wndReport.Populate();


Then let me describe some details for you.

1. In regular (non-virtual) mode Report Control stores data (Records and Record Items) in its internal collection.
 
2. In virtual mode report control does not store data (except the only  single record to know data structure). But it also stores records count and requests only portion of data which is necessary to display.

This is useful if you already have a data storage (a collection of objects or even a DataBase). In this mode data is not duplicated in your storage and Report's storage and you do not need to synchronize both data collections.

As I understand you read data in another thread and want to add records to report control in run-time; also you do not have a big amount of records. So far I think that you do not need to use a virtual mode there.

Just simply add new records to the control's collection and call Populate() after every bunch (50-100, 200) of records was added.

--
WBR,
Serge




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net