Print Page | Close Window

Problem Loading Records from XML

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=16178
Printed Date: 26 June 2024 at 10:25am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Problem Loading Records from XML
Posted By: Algae
Subject: Problem Loading Records from XML
Date Posted: 11 February 2010 at 5:36pm
Problem: When loading Records from an XML file, RecordItems end up in wrong columns. Any suggestions on how to correct this?

For example:

Initial report looks like:

col 1 | col 2 | col 3
---------------------
a      |   b    |  c

Save the report, load it, everything is fine.

Now rearrange the columns, by dragging and dropping. So far so good record items are in the correct columns.

col 1 | col 3 | col 2
---------------------
a          c        b

Save this new configuration. Load it again. As illustrated, the columns are fine, but the record items no longer correspond with the proper column!

col 1 | col 3 | col 2
---------------------
a           b       c

The basic mechanism used is shown here with the exception of my column load/save function.

saving:

CXTPPropExchangeXMLNode px(FALSE, 0, _T("ReportControl"));
       
// save columns

// save records
CXTPPropExchangeSection secRecords(px.GetSection(_T("Records")));
GetReportCtrl().GetRecords()->DoPropExchange(&secRecords);

// save column configuration
GetReportCtrl().DoPropExchange(&px);

px.SaveToFile(sReportName);

loading:

CXTPPropExchangeXMLNode px(TRUE, 0, _T("ReportControl"));

if (!px.LoadFromFile(sReportPath))
     return FALSE;

px.ExchangeLocale();

GetReportCtrl().ResetContent();
GetReportCtrl().GetColumns()->Clear();

// load columns

// load records
CXTPPropExchangeSection secRecords(px.GetSection(_T("Records")));
GetReportCtrl().GetRecords()->DoPropExchange(&secRecords);

// set column properties
GetReportCtrl().DoPropExchange(&px);


VS2008
CJ 13.2.2




Replies:
Posted By: Algae
Date Posted: 17 February 2010 at 3:11pm
Solved.

The problem was I was saving columns based on position not by index! Doh. Changed "GetAt" to Find and it works perfectly.

    CXTPPropExchangeSection secColumns(pPX->GetSection(_T("ColumnNames")));
    DWORD nColumnCount = GetReportCtrl().GetColumns()->GetCount();
    CXTPPropExchangeEnumeratorPtr pEnumColumns(secColumns->GetEnumerator(_T("Column")));
    POSITION posColumn = pEnumColumns->GetPosition(nColumnCount);
    for (DWORD i = 0; i < nColumnCount; i++)
    {
        CXTPPropExchangeSection secColumn(pEnumColumns->GetNext(posColumn));
        CXTPReportColumn* pColumn = GetReportCtrl().GetColumns()->Find(i); // was getat <<<



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