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 » How can I store the column order poition in a "CExtGridWnd"? Collapse All
Subject Author Date
Francesco Toscano Jan 21, 2008 - 12:20 PM

Is it possible to store the current displayed order of the columns of "CExtGridWnd", that is changed after column header drag and drop?

Thank ... many many thanks for your great support.


Technical Support Jan 24, 2008 - 12:54 AM

The main question is how to identify each column after it was created and its position has been changed by the user. All cell classes have the LParamSet() and LParamGet() methods. This allows you to assign some user data. So just use these parameters to mark your header cells with some unique data.

Then you need to save/restore information about the column order. We don’t have a ready-to-use solution for this but we have another solution. In some of our projects we use the code below which saves column widths in a string. This string can be saved in the registry. Then we restore columns width using information from the parsed string. You can use this code as a sample.

bool CBaseGridWnd::LoadColumnWidths()
{
            ASSERT_VALID( this );

            CSettings cfg;
            CString sWidths;
            if( !cfg.GetGridColumnWidths(
                                   sWidths,
                                   m_sSection,
                                   m_sEntry
                                   )
                        )
                        return false;
            if( sWidths.IsEmpty() )
                        return false;

            CString sToken;
            LONG nColNo = 0;
            LONG nColumnCount = ColumnCountGet();
            for( INT i = 0; i < sWidths.GetLength(); i++ )
            {
                        if( nColNo > nColumnCount - 1 )
                                   break;
                        if( sWidths.GetAt( i ) != _T(’;’) )
                        {
                                   sToken += sWidths.GetAt( i );
                        }
                        else
                        {
                                   CExtGridCellHeader * pCell =
                                               STATIC_DOWNCAST(
                                                           CExtGridCellHeader,
                                                           GridCellGetOuterAtTop(
                                                                       nColNo,
                                                                       0L,
                                                                       RUNTIME_CLASS( CExtGridCellHeader )
                                                                       )
                                                           );
                                   if( pCell != NULL )
                                   {
                                               ASSERT_VALID( pCell );
                                               INT nItemExtent = _ttoi( sToken );
                                               pCell->ExtentSet( nItemExtent );
                                   }

                                   sToken = _T("");
                                   nColNo++;
                        }
            }           
            return true;
}

bool CBaseGridWnd::SaveColumnWidths()
{
            ASSERT_VALID( this );

            if( !m_bEnableSaveRestore )
                        return false;

            CString sWidths;
            LONG nColumnCount = ColumnCountGet();
            for( LONG nColNo = 0L; nColNo < nColumnCount; nColNo++ )
            {
                        CExtGridCellHeader * pCell =
                                   STATIC_DOWNCAST(
                                               CExtGridCellHeader,
                                               GridCellGetOuterAtTop(
                                                           nColNo,
                                                           0L,
                                                           RUNTIME_CLASS( CExtGridCellHeader )
                                                           )
                                               );
                        if( pCell != NULL )
                        {
                                   ASSERT_VALID( pCell );
                                   INT nItemExtent = 0;
                                   if( pCell->ExtentGet( nItemExtent ) )
                                   {
                                               CString s;
                                               s.Format( _T("%d;"), nItemExtent );
                                               sWidths += s;
                                   }
                        }
            }           
            
            CSettings cfg;
            if( !cfg.SetGridColumnWidths(
                                   sWidths,
                                   LPCTSTR( m_sSection ),
                                   LPCTSTR( m_sEntry )
                                   )
                        )
                        return false;

            return true;
}