Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » CExtReportGridWnd::ReportColumnRename Collapse All
Subject Author Date
Suhai Gyorgy Jul 24, 2007 - 3:12 AM

Dear Support,

I’m trying to use the above method, but it doesn’t seem to work. I’ve stepped through its code and I can’t see any code which would assign the new name to the column. Very close to the end of the method, I can see this line:

m_mapColumns.SetAt( pMovingRGC, pMovingRGC );

I guess this line is supposed to assign the new name, but with different second parameter. I’ve tested it with both old and new category names being NULL, old column name being name of an existing column, so pMovingRGC is a valid pointer.

Please, advise! (Using v2.64.1)

Technical Support Jul 24, 2007 - 2:18 PM

This method requires the exact names of categories or NULL if you are going to rename a column only without changing its owner category. Please let us know the exact set of parameters which we should use to test this method. We guess we can easily check any problem with column renaming using the ReportGrid sample.

Suhai Gyorgy Jul 24, 2007 - 3:51 PM

To reproduce the problem (Column name does not change), change your ReportGrid as so:

1. When Registering "Name" column, change it’s category to NULL in InitReportGridContent:
    ReportColumnRegister(
        _T("Name"),
        NULL,
        bInitiallyActive,
        false
        );

2. I’ve put the testing code in OnRgExportToExcel:
void CChildView::OnRgExportToExcel()
{
    ReportColumnRename(_T("Name"), NULL, _T("Testing ReportColumnRename..."), NULL);
    return;
    ...
}


For the test to reproduce the problem, Registry has to be clean of sample application’s settings.
ReportColumnRename returns true, and stepping through its code I can see that OnSwDoRedraw() is called (When calling OnSwDoRedraw() myself, after ReportColumnRename, result is the same), column name is not changed in column header.

Technical Support Jul 25, 2007 - 4:15 AM

Thank you for your comments. We changed the method signature and body because it logically requires two first parameters to be specified:

      bool ReportColumnRename(
            __EXT_MFC_SAFE_LPCTSTR strColumnNameOld,
            __EXT_MFC_SAFE_LPCTSTR strCategoryNameOld,
            __EXT_MFC_SAFE_LPCTSTR strColumnNameNew = NULL,
            __EXT_MFC_SAFE_LPCTSTR strCategoryNameNew = NULL,
            bool bRedraw = true
            );

bool CExtReportGridWnd::ReportColumnRename(
      __EXT_MFC_SAFE_LPCTSTR strColumnNameOld,
      __EXT_MFC_SAFE_LPCTSTR strCategoryNameOld,
      __EXT_MFC_SAFE_LPCTSTR strColumnNameNew, // = NULL
      __EXT_MFC_SAFE_LPCTSTR strCategoryNameNew, // = NULL
      bool bRedraw // = true
      )
{
      ASSERT_VALID( this );
      if(         strColumnNameOld == NULL
            ||    _tcslen( strColumnNameOld ) == 0
            )
            return false;
      if(         strCategoryNameOld == NULL
            ||    _tcslen( strCategoryNameOld ) == 0
            )
            return false;
      if(         strColumnNameNew == NULL
            ||    _tcslen( strColumnNameNew ) == 0
            )
            strColumnNameNew = strColumnNameOld;
      if(         strCategoryNameNew == NULL
            ||    _tcslen( strCategoryNameNew ) == 0
            )
            strCategoryNameNew = strCategoryNameOld;
LONG nIndex, nCount;
CExtReportGridColumn * pMovingRGC = NULL;
CTypedPtrArray < CPtrArray, CExtReportGridColumn * >
            * pArrCategoryColumns = NULL;
      if( _tcscmp(strCategoryNameNew,strCategoryNameOld) != 0 )
      {
            if(   m_mapColumnCategories.Lookup(
                        strCategoryNameOld,
                        (void*&)pArrCategoryColumns
                        )
                  )
            {
                  ASSERT( pArrCategoryColumns != NULL );
                  nCount = LONG( pArrCategoryColumns->GetSize() );
                  ASSERT( nCount > 0 );
                  if( nCount > 1 )
                  {
                        for( nIndex = 0; nIndex < nCount; nIndex ++ )
                        {
                              CExtReportGridColumn * pRGC =
                                    pArrCategoryColumns->GetAt( nIndex );
                              ASSERT_VALID( pRGC );
                              ASSERT( pRGC->m_pRGW == this );
                              if( _tcscmp(
                                          pRGC->ColumnNameGet(),
                                          strColumnNameOld
                                          ) == 0
                                    )
                              {
                                    pMovingRGC = pRGC;
                                    pArrCategoryColumns->RemoveAt( nIndex );
                                    break;
                              }
                        } // for( nIndex = 0; nIndex < nCount; nIndex ++ )
                        if( pMovingRGC == NULL )
                              return false; // not found
                        ASSERT_VALID( pMovingRGC );
                  } // if( nCount > 1 )
                  else
                  {
                        ASSERT( nCount == 1 );
                        pMovingRGC = pArrCategoryColumns->GetAt( 0 );
                        ASSERT_VALID( pMovingRGC );
                        if(   _tcscmp(
                                    pMovingRGC->ColumnNameGet(),
                                    strColumnNameOld
                                    ) != 0
                              )
                              return false; // not found
                        delete pArrCategoryColumns;
                        m_mapColumnCategories.RemoveKey( strCategoryNameOld );
                        OnReportGridColumnCategoryRemoved( strCategoryNameOld );
                  } // else from if( nCount > 1 )
            }
            ASSERT_VALID( pMovingRGC );
            pArrCategoryColumns = NULL;
            if(   ! m_mapColumnCategories.Lookup(
                        strCategoryNameNew,
                        (void*&)pArrCategoryColumns
                        )
                  )
            {
                  pArrCategoryColumns = new
                        CTypedPtrArray < CPtrArray, CExtReportGridColumn * >;
                  m_mapColumnCategories.SetAt( strCategoryNameNew, pArrCategoryColumns );
                  OnReportGridColumnCategoryAdded( strCategoryNameNew );
            }
#ifdef _DEBUG
            else
            {
                  ASSERT( pArrCategoryColumns != NULL );
            }
#endif // _DEBUG
            pArrCategoryColumns->Add( pMovingRGC );
      } // if( _tcscmp(strCategoryNameNew,strCategoryNameOld) != 0 )
      else
      {
            if(   _tcscmp(
                        strColumnNameOld,
                        strColumnNameNew
                        ) == 0
                  )
                  return true; // both names are equal
            if(   ! m_mapColumnCategories.Lookup(
                        strCategoryNameNew,
                        (void*&)pArrCategoryColumns
                        )
                  )
                  return false; // not found
            ASSERT( pArrCategoryColumns != NULL );
            nCount = LONG( pArrCategoryColumns->GetSize() );
            ASSERT( nCount > 0 );
            for( nIndex = 0; nIndex < nCount; nIndex ++ )
            {
                  CExtReportGridColumn * pRGC =
                        pArrCategoryColumns->GetAt( nIndex );
                  ASSERT_VALID( pRGC );
                  ASSERT( pRGC->m_pRGW == this );
                  if( _tcscmp(
                              pRGC->ColumnNameGet(),
                              strColumnNameOld
                              ) == 0
                        )
                  {
                        pMovingRGC = pRGC;
                        break;
                  }
            } // for( nIndex = 0; nIndex < nCount; nIndex ++ )
            if( pMovingRGC == NULL )
                  return false; // not found
            ASSERT_VALID( pMovingRGC );
      } // else from if( _tcscmp(strCategoryNameNew,strCategoryNameOld) != 0 )
      ASSERT_VALID( pMovingRGC );
      m_mapColumns.SetAt( pMovingRGC, pMovingRGC );
      pMovingRGC->CExtGridCellHeader::TextSet( strColumnNameNew );
      if( bRedraw && GetSafeHwnd() != NULL )
      {
            OnSwUpdateScrollBars();
            OnSwDoRedraw();
      } // if( bRedraw && GetSafeHwnd() != NULL )
      return true;
}
Now you can use this method for renaming columns:
void CChildView::OnRgExportToExcel() 
{
//    ReportColumnRename( _T("Name"), NULL, _T("Testing ReportColumnRename..."), NULL );
      ReportColumnRename( _T("Name"), _T("Main Information"), _T("Testing ReportColumnRename..."), NULL );
return;
}


Suhai Gyorgy Jul 25, 2007 - 5:30 AM

This looks good (haven’t tested it yet), but I won’t be able to use it in my case.

In our application, we don’t have many columns, so I didn’t set any category names for them when registering ( strCategoryName parameter of ReportColumnRegister is always NULL). I also disabled Field Chooser dialog (the command for displaying it has been removed from context menu of reportgrid), so not having a category name doesn’t produce any problems. But now I won’t be able to use ReportColumnRename as I can’t fill second parameter to be valid.

If ReportColumnRegister allows a column to be registered without category, renaming should work as well.

Technical Support Jul 25, 2007 - 8:14 AM

Yes, the last version of the CExtReportGridWnd::ReportColumnRename() method does not allow empty column/category names nor NULL values in first two parameters. We think we can enable empty and NULL category names but not column names. Please modify the beginning of this method:

bool CExtReportGridWnd::ReportColumnRename(
      __EXT_MFC_SAFE_LPCTSTR strColumnNameOld,
      __EXT_MFC_SAFE_LPCTSTR strCategoryNameOld,
      __EXT_MFC_SAFE_LPCTSTR strColumnNameNew, // = NULL
      __EXT_MFC_SAFE_LPCTSTR strCategoryNameNew, // = NULL
      bool bRedraw // = true
      )
{
      ASSERT_VALID( this );
      if(         strColumnNameOld == NULL
            ||    _tcslen( strColumnNameOld ) == 0
            )
            return false;
      if(         strCategoryNameOld == NULL
            ||    _tcslen( strCategoryNameOld ) == 0
            )
            strCategoryNameOld = _T(""); // THIS LINE WAS ADDED
//          return false; // THIS LINE WAS COMMENTED
      if(         strColumnNameNew == NULL
            ||    _tcslen( strColumnNameNew ) == 0
            )
            strColumnNameNew = strColumnNameOld;
      if(         strCategoryNameNew == NULL
            ||    _tcslen( strCategoryNameNew ) == 0
            )
            strCategoryNameNew = strCategoryNameOld;
. . .