Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Report Control
  New Posts New Posts RSS Feed - Problem Loading Records from XML
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Problem Loading Records from XML

 Post Reply Post Reply
Author
Message
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post Topic: Problem Loading Records from XML
    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

Back to Top
Algae View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 January 2007
Location: United States
Status: Offline
Points: 217
Post Options Post Options   Thanks (0) Thanks(0)   Quote Algae Quote  Post ReplyReply Direct Link To This Post 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 <<<
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.