Professional UI Solutions
Site Map   /  Register
 
 
 

Report Grid

How to set the text color and the background color for a whole row?

You should set these colors for each cell in a row. Here is an example of how you can achieve this by overriding two methods SetRowColorBack() and SetRowColorText() in a CExtReportGridWnd-derived class.

class CBaseReportGridWnd : public CExtReportGridWnd
{
public:
    CBaseReportGridWnd();
    virtual ~CBaseReportGridWnd();

. . .

    void SetRowColorBack(
        CExtReportGridItem * pRGI, 
        COLORREF clrBkColor = COLORREF( -1L ),
        CExtGridCell::e_cell_state_t eCellState = CExtGridCell::__ECS_NORMAL
        );
    void SetRowColorText(
        CExtReportGridItem * pRGI, 
        COLORREF clrTextColor = COLORREF( -1L ),
        CExtGridCell::e_cell_state_t eCellState = CExtGridCell::__ECS_NORMAL
        );

. . . 
    
};
void CBaseReportGridWnd::SetRowColorBack(
    CExtReportGridItem * pRGI, 
    COLORREF clrBkColor, // = COLORREF( -1L )
    CExtGridCell::e_cell_state_t eCellState // = CExtGridCell::__ECS_NORMAL
    )
{
    ASSERT_VALID( this );
    if( pRGI == NULL )
    {
        ASSERT( FALSE );
        return;
    }
    ASSERT_VALID( pRGI );
    for( POSITION pos = ReportColumnGetStartPosition(); pos != NULL; )
    {
        const CExtReportGridColumn * pRGC = ReportColumnGetNext( pos );
        ASSERT_VALID( pRGC );

        CExtGridCellEx * pCell =
            STATIC_DOWNCAST(
                CExtGridCellEx,
                ReportItemGetCell( 
                    pRGC,
                    pRGI, 
                    RUNTIME_CLASS( CExtGridCellEx ) 
                    )
                );
        if( pCell != NULL )
        {
            ASSERT_VALID( pCell );
            pCell->BackColorSet( 
                eCellState, 
                clrBkColor 
                );
        }
    }
}

void CBaseReportGridWnd::SetRowColorText(
    CExtReportGridItem * pRGI, 
    COLORREF clrTextColor, // = COLORREF( -1L )
    CExtGridCell::e_cell_state_t eCellState // = CExtGridCell::__ECS_NORMAL
    )
{
    ASSERT_VALID( this );
    if( pRGI == NULL )
    {
        ASSERT( FALSE );
        return;
    }
    ASSERT_VALID( pRGI );
    for( POSITION pos = ReportColumnGetStartPosition(); pos != NULL; )
    {
        const CExtReportGridColumn * pRGC = ReportColumnGetNext( pos );
        ASSERT_VALID( pRGC );

        CExtGridCellEx * pCell =
            STATIC_DOWNCAST(
                CExtGridCellEx,
                ReportItemGetCell( 
                    pRGC,
                    pRGI, 
                    RUNTIME_CLASS( CExtGridCellEx ) 
                    )
                );
        if( pCell != NULL )
        {
            ASSERT_VALID( pCell );
            pCell->TextColorSet( 
                eCellState, 
                clrTextColor 
                );
        }
    }
}

How to sort and group data in the report grid programmatically?

There is a CExtReportGridSortOrder class that allows you to set sorting and grouping rules for the report grid. You can pass an instance of this class to a report grid using the CExtReportGridWnd.ReportSortOrderSet() method. Here is sample code that shows how the report grid can be sorted and grouped by two columns:

CExtReportGridWnd & wndReportGrid = . . .
CExtReportGridColumn * pRGC1 = . . .
CExtReportGridColumn * pRGC2 = . . . 
bool bAscending1 = . . .
bool bAscending2 = . . .
CExtReportGridSortOrder rgso;
rgso.ColumnInsert( pRGC1, -1, bAscending1 ); 
rgso.ColumnInsert( pRGC2, -1, bAscending2 );
rgso.ColumnGroupCountSet( 2 );
wndReportGrid.ReportSortOrderSet( rgso, false, true );
wndReportGrid.ReportSortOrderUpdate(true);

You can also cancel any applied rules by passing an empty CExtReportGridSortOrder object to ReportSortOrderSet():

CExtReportGridSortOrder rgsoEmpty;
wndReportGrid.ReportSortOrderSet( rgsoEmpty, false, true );

How to enable automatic column sizing for my grid?

You can set up your grid in a way that, regardless of it size, the columns will always take up the entire width of the grid's client area without displaying the horizontal scroll bar. To see how this works, run the ReportGrid sample and make sure that Report Grid | Behavior | Use Column Auto-Sizing is checked. To enable this option in your grid (any class derived from CExtGridWnd including CExtReportGrid), follow these steps:

1) Apply the __EGBS_BSE_EX_PROPORTIONAL_COLUMN_WIDTHS style to the grid window using the CExtGridWnd::BseModifyStyleEx() method.

2) Specify the weight of each column (i.e., how the column's width should change) using the CExtGridCell::ExtentPercentSet() method of the column header cell. The weight values should be in the range of 0.0 to 1.0.

3) Keep in mind that you can also set the initial, minimum, and maximum width for each column using the CExtGridCell::ExtentSet() of the header cell. The column will be not resizable at all, if these width values are equal to each other.


If you have any questions, please visit our forum or contact our technical support team at support@prof-uis.com.