Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Report Control
  New Posts New Posts RSS Feed - Bug in updating report control
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Bug in updating report control

 Post Reply Post Reply
Author
Message
csunita View Drop Down
Groupie
Groupie


Joined: 14 July 2008
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote csunita Quote  Post ReplyReply Direct Link To This Post Topic: Bug in updating report control
    Posted: 08 September 2008 at 6:24pm

uploads/20080908_182308_ReportControl.zip

Hello,

I have to update report control columns automatically depending on the selection. For example, Column5 = Column1 + Column3 & Column1 = Column5 - Column3 etc

One complication is that some of the columns can be changed dynamically by the user, depending on which column is currenty visible, Column5 could then become sum of col1 + col4 for e.g.
I could not do this in the OnEditChanged() of the CXTPReportRecordItem because I was unable to determine how to find out if the record item was visible or not.
I manually update everything in the ON_NOTIFY(XTP_NM_REPORT_VALUECHANGED, IDC_BEFORE_CNCTN, OnBeforeCnctnValueChanged) function. Code is attached.
Here is the problem. Let's say currenty I have visble col 0, 1, 2, 3, and 5. Col5 is sum of col1 & 3. If I change col1, col5 gets updated correctly.
However, if I now change col5, col1 is supposed to automatically update as difference of col5 and 3. But I am unable to update col5 once I enter values in col1, and col5 updates automatically.
 
Code is copied here: The .h and .cpp files are attached.
 
void CConsumptionDlg::OnBeforeCnctnValueChanged(NMHDR*  pNotifyStruct, LRESULT* result)
{
    XTP_NM_REPORTRECORDITEM* pItemNotify = (XTP_NM_REPORTRECORDITEM*) pNotifyStruct;
    ASSERT(pItemNotify != NULL);
    int row = pItemNotify->pRow->GetIndex();
    int col = pItemNotify->pColumn->GetIndex();
   
    pFinalCurrent->SetCaption("Final Current [mA]");
    double dFinalCrnt, dLEDCrnt, dDongleCrnt;
    CString strFinalCrnt, strLEDCrnt, strDongleCrnt;
    if ( pLEDCurrent->IsVisible() )
    {
        // LED Current cannot be edited, and does not need to be updated
        strLEDCrnt = m_Report_b4_cnctn.GetRecords()->GetAt(row)->GetItem(COLUMN_LED_CRNT)->GetCaption(pLEDCurrent);
        dLEDCrnt = atof(strLEDCrnt);
        // Either Dongle Current column changed:
        if (col == COLUMN_DONGLE_ACTIVE)
        {
            strDongleCrnt = pItemNotify->pItem->GetCaption(pDongleCurrent);
            //strDongleCrnt = pItemNotify->pItem->GetItemData();
            dDongleCrnt = atof(strDongleCrnt);
            // Update the Final Current:
            strFinalCrnt.Format("%.2f", (dDongleCrnt+dLEDCrnt) );
            m_Report_b4_cnctn.GetRecords()->GetAt(row)->GetItem(COLUMN_FINAL_CRNT)->SetCaption(strFinalCrnt);
        }
        // Or Final Current column changed:
        else if (col == COLUMN_FINAL_CRNT )
        {
            strFinalCrnt = pItemNotify->pItem->GetCaption(pFinalCurrent);
            //strFinalCrnt = pItemNotify->pItem->GetItemData();
            dFinalCrnt = atof(strFinalCrnt);
            // Update the Dongle Current:
            strDongleCrnt.Format("%.2f", (dFinalCrnt - dLEDCrnt));
            m_Report_b4_cnctn.GetRecords()->GetAt(row)->GetItem(COLUMN_DONGLE_ACTIVE)->SetCaption(strDongleCrnt);
        }
    }
    // Customer LED current has been selected
    else
    {
        // Donlge Current has changed
        if (col == COLUMN_DONGLE_ACTIVE) 
        {
            strDongleCrnt = pItemNotify->pItem->GetCaption(pDongleCurrent);
            //strDongleCrnt = pItemNotify->pItem->GetItemData();
            dDongleCrnt = atof(strDongleCrnt);
            strLEDCrnt = m_Report_b4_cnctn.GetRecords()->GetAt(row)->GetItem(COLUMN_USER_LED_CRNT)->GetCaption(pLEDCurrentCstmr);
            dLEDCrnt = atof(strLEDCrnt);
            // ------  Update the Final Current ------
            strFinalCrnt.Format("%.2f", (dDongleCrnt+dLEDCrnt) );
            m_Report_b4_cnctn.GetRecords()->GetAt(row)->GetItem(COLUMN_FINAL_CRNT)->SetCaption(strFinalCrnt);
        }       
        // Customer LED Current has changed
        else if (col == COLUMN_USER_LED_CRNT)
        {
            strLEDCrnt = pItemNotify->pItem->GetCaption(pLEDCurrentCstmr);
            //strLEDCrnt = pItemNotify->pItem->GetItemData();
            dLEDCrnt = atof(strLEDCrnt);
            strDongleCrnt = m_Report_b4_cnctn.GetRecords()->GetAt(row)->GetItem(COLUMN_DONGLE_ACTIVE)->GetCaption(pDongleCurrent);
            dDongleCrnt = atof(strDongleCrnt);           
            // ------  Update the Final Current ------
            strFinalCrnt.Format("%.2f", (dDongleCrnt+dLEDCrnt) );
            m_Report_b4_cnctn.GetRecords()->GetAt(row)->GetItem(COLUMN_FINAL_CRNT)->SetCaption(strFinalCrnt);
        }
        // Final Current column has changed
        else if (col == COLUMN_FINAL_CRNT )
        {
            strFinalCrnt = pItemNotify->pItem->GetCaption(pFinalCurrent);
            //strFinalCrnt = pItemNotify->pItem->GetItemData();
            dFinalCrnt = atof(strFinalCrnt);
            strLEDCrnt = m_Report_b4_cnctn.GetRecords()->GetAt(row)->GetItem(COLUMN_USER_LED_CRNT)->GetCaption(pLEDCurrentCstmr);
            dLEDCrnt = atof(strLEDCrnt);
            // ------ Update the Dongle Current ------
            strDongleCrnt.Format("%.2f", (dFinalCrnt - dLEDCrnt));
            m_Report_b4_cnctn.GetRecords()->GetAt(row)->GetItem(COLUMN_DONGLE_ACTIVE)->SetCaption(strDongleCrnt);
        }
    }
    
    m_Report_b4_cnctn.Populate();
    m_Report_b4_cnctn.RedrawControl();
    m_Report_b4_cnctn.AllowEdit(TRUE);
    m_Report_b4_cnctn.FocusSubItems(TRUE);
 m_Report_b4_cnctn.SetFocus();
 
Back to Top
csunita View Drop Down
Groupie
Groupie


Joined: 14 July 2008
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote csunita Quote  Post ReplyReply Direct Link To This Post Posted: 08 September 2008 at 6:28pm

little more clarification:

if i change col1 first, col5 updates as it should. or if chage col5 first, col1 updates as it should.

but if i first change col1, even multiple times, it works. after that, if i try to change col5, then i am not unable to change/update col5.

similarly, if i change col5 first, i can do this multiple times, but as soon as i change col 1, i am unable to do so. it keeps on repeating the same value.

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.172 seconds.