Print Page | Close Window

Update all cells in row when constraint is changed

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=20600
Printed Date: 16 November 2024 at 11:57am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Update all cells in row when constraint is changed
Posted By: shanmuganathan
Subject: Update all cells in row when constraint is changed
Date Posted: 07 February 2013 at 5:01am
Hello All,

I am using XT version 15.
Each column has its own constraint list which drops down when clicked in the cell

Requirement :  when column 2 (Record_0) selection is made, It should automatically update that row from the respective constraint list of each combo


Example : If option "4" is selected in column 2 (Record_0) combo list, it should update that row like
"4" "44" "444" "4444" "44444" which are in the constraint list of column 3,4,5,6
-------------------------------
Sample Code : (Tried)

m_xtReport.ModifyStyle ( NULL, WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP );
m_xtReport.GetReportHeader ( )->AllowColumnRemove ( FALSE );
m_xtReport.GetReportHeader ( )->AllowColumnReorder ( FALSE );
m_xtReport.GetReportHeader ( )->AllowColumnSort ( FALSE );
m_xtReport.EnableScrollBar ( SB_HORZ, TRUE );   

//---Add Columns and Constratints---//
int nRecd = 0; nCol = 0;

//Adding Grid Field
CXTPReportColumn* pGridColumn = m_xtReport.AddColumn ( new CXTPReportColumn ( nCol, "Grid", 300) );
if( pGridColumn )
{
    pGridColumn->SetSortable(FALSE);
    pGridColumn->GetEditOptions ( )->m_bAllowEdit =FALSE;   
}

//Adding Record_0
csCol.Format("Record_%d",nRecd); nRecd++; nCol++;
CXTPReportColumn* pRcrd1_Column = m_xtReport.AddColumn ( new CXTPReportColumn ( nCol, csCol, 300) );
if( pRcrd1_Column )
{
    //Adding combo list
    pRcrd1_Column->GetEditOptions ( )->AddConstraint ( "1", 0 );
    pRcrd1_Column->GetEditOptions ( )->AddConstraint ( "2", 1 );
    pRcrd1_Column->GetEditOptions ( )->AddConstraint ( "3", 2 );
    pRcrd1_Column->GetEditOptions ( )->AddConstraint ( "4", 3 );
    pRcrd1_Column->GetEditOptions ( )->AddConstraint ( "5", 4 );

    pRcrd1_Column->GetEditOptions ( )->m_bConstraintEdit = FALSE;
    pRcrd1_Column->GetEditOptions ( )->m_bAllowEdit =FALSE;// TRUE;
    pRcrd1_Column->GetEditOptions ( )->m_bSelectTextOnEdit =FALSE;// TRUE;
    pRcrd1_Column->GetEditOptions ( )->m_nMaxLength = 240;
    pRcrd1_Column->GetEditOptions ( )->AddComboButton ( );       
}

//Adding Record_1 ....
//Adding Record_2 .... etc...

//---Add records to report control---//
m_xtReport.AddRecord ( new CPxRecord () );
--

class CPxRecord : public CXTPReportRecord
{
public:
 CPxRecord(void)
 {
    //Sample show to add first row alone
    AddItem( new CXTPReportRecordItemText("1"));
    AddItem( new CXTPReportRecordItemText("11"));
    AddItem( new CXTPReportRecordItemText("111"));
    AddItem( new CXTPReportRecordItemText("111"));
    AddItem( new CXTPReportRecordItemText("1111"));
    AddItem( new CXTPReportRecordItemText("11111"));   
 }
 virtual ~CPxRecord(void);
}

//---Handle XTP_NM_REPORT_VALUECHANGED and update the row---//

//ON_NOTIFY(XTP_NM_REPORT_VALUECHANGED, IDC_GRID, OnReportValueChanged)

void CXmlDlg::OnReportValueChanged(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();   

    CString cs(""), csData("");       

    //Get caption selected from combo
    cs = pItemNotify->pItem->GetCaption( pItemNotify->pColumn );   

    //search in the constraint
    CXTPReportRecordItemConstraint* pcnst = pItemNotify->pColumn->GetEditOptions()->FindConstraint(cs);

    //get the caption index
    int nIndex = pcnst->GetIndex();
   
    CXTPReportColumns    *pAllColumns = NULL;   
    CXTPReportRecords    *pAllRecords = NULL;

    pAllColumns = m_xtReport.GetColumns ( );
    int nRecordCount = pAllColumns->GetCount();

    pAllRecords = m_xtReport.GetRecords ( );

    for(int nItr = 0; nItr < nRecordCount-1; nItr++)
    {
        CXTPReportRecordItem *pItem = NULL;
        CXTPReportColumn    *pFieldColumn = NULL;       
        CXTPReportRecordItemConstraint* pcnstEx = NULL;
        CXTPReportRecord    *pOneRecord = NULL;

        if( nItr != 0 )    //leave first column
        {
            pOneRecord = pAllRecords->GetAt(nItr);
            pFieldColumn = pAllColumns->GetAt(nItr);
            pItem = pOneRecord->GetItem ( pFieldColumn );

            //Note : Data in all the constratint are indexed
            pItem->SetItemData(nIndex);    //set the constraint index for each cell of that row
        }       
    }

    m_xtReport.Populate();
}

Thanks



Replies:
Posted By: GRLEX
Date Posted: 22 February 2013 at 4:38am
Hello. try:
..............
void CXmlDlg::OnReportValueChanged(NMHDR * pNotifyStruct, LRESULT * result)
{
    XTP_NM_REPORTRECORDITEM* pItemNotify = (XTP_NM_REPORTRECORDITEM*) pNotifyStruct;
        ASSERT(pItemNotify != NULL);
int iItemInd = pItemNotify->pItem->GetIndex();
CXTPReportRecord * pRec = pItemNotify->pItem->GetRecord();

CString sText = pItemNotify->pItem->GetCaption();

for(int i = iItemInd + 1; i < pGrid->GetColumns()->GetCount(); i++)
{
CXTPReportRecordItem * pItem = pRecord->GetItem(i);
pItem->SetCaption(sText);
}
..........................

code may be with small spelling mistakes cause i wrote it in notepad :). But concept must be true



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