Professional UI Solutions
Site Map   /  Register


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 General Discussion » ReportGrid: changing color for selection if no focus Collapse All
Subject Author Date
Martin Baumgaertner Oct 11, 2007 - 2:43 PM

Hello ProfUIS-Team,

in a dialog that holds a customized ReportGrid it’s possible to change the selection of a whole row in the grid window by setting a search string in an edit control. While programmatically selecting the intended row works fine, the selection color appears much too weak to be clearly visible.

How can I modify the intensity and/or the color itself (background, text) for the case that my grid does NOT have the focus?

Best regards,


Technical Support Nov 1, 2007 - 12:55 PM

The instances of the CExtReportGridColumn classes are used as header cells in the top outer header row:

CExtReportGridColumn * pRGC = STATIC_DOWNCAST( CExtReportGridColumn, pReportGridWnd->GridCellGetOuterAtTop( nColNo, 0L ) );

Martin Baumgaertner Oct 31, 2007 - 8:03 AM

Now there’s only one question left:

how can I convert the nColNo parameter into a pointer to the corresponding CExtReportGridColumn object in order to colorize this column’s selection different? i.e. it’s necessary to extract the column number using the column’s name for comparison kind of:

if (nColNo == nNamedColNo)
     clrCustomCellBackground = RGB(_red,_green,_blue);

Martin Baumgaertner Oct 30, 2007 - 12:50 PM

Thank you very much! Now everything works fine.


Martin Baumgaertner Oct 19, 2007 - 3:36 AM

Dear ProfUIS-Team,

sorry for asking again, but is there a solution for my last question?

Best regards,


Technical Support Oct 22, 2007 - 12:37 PM

We are sorry for the delay with this reply. The solution described in our previous answer is good for CExtGridWnd but not for CExtReportGridWnd. In the latter case, you should implement the CExtGridWnd::OnGridHookCellPaintBackground() virtual method. The following test version of this method can be added to the CChildView class in the ReportGrid sample and you will see how different cells in each data row painted with a different selection color

      virtual bool OnGridHookCellPaintBackground(
            const CExtGridCell & _cell,
            CDC & dc,
            LONG nVisibleColNo,
            LONG nVisibleRowNo,
            LONG nColNo,
            LONG nRowNo,
            INT nColType,
            INT nRowType,
            const RECT & rcCellExtra,
            const RECT & rcCell,
            const RECT & rcVisibleRange,
            DWORD dwAreaFlags,
            DWORD dwHelperPaintFlags
            ) const
            if(         nColType == 0
                  &&    nRowType == 0
                  &&    SelectionGetForCellPainting( nColNo, nRowNo )
                  COLORREF clrCustomCellBackground = RGB(128,128,128);
                  if( nColNo == 0 )
                        clrCustomCellBackground = RGB(255,0,0);
                  else if( nColNo == 1 )
                        clrCustomCellBackground = RGB(0,255,0);
                  else if( nColNo == 2 )
                        clrCustomCellBackground = RGB(0,0,255);
                  else if( nColNo == 3 )
                        clrCustomCellBackground = RGB(255,255,0);
                  else if( nColNo == 4 )
                        clrCustomCellBackground = RGB(0,255,255);
                  else if( nColNo == 5 )
                        clrCustomCellBackground = RGB(255,0,255);
                  dc.FillSolidRect( &rcCellExtra, clrCustomCellBackground );
                  return true;
You can also override the CExtGridWnd::OnGridCellQueryTextColor() virtual method to provide different grid cells with different text colors. The CExtTreeGridWnd::ItemGetByVisibleRowIndex() method can be used for converting nRowNo (a plain row number) into a HTREEITEM tree row handle which is really a pointer CExtReportGridItem*. Tree items which have zero child items are data rows in the report grid control. All the other tree items are group rows.

Martin Baumgaertner Oct 15, 2007 - 10:29 AM

Thank you for your answer.

I tried your suggestion but unfortunately it seems not to solve my problem, which is that the grid does NOT have the focus when changing selection programmatically. In this case where the focus should stay in the edit control for further typing, the highlighting of the selected row is much too light.

As a crude workaround I tried the following:

CMyGridWnd::OnGbwPaintCell (
	CDC & dc,
	LONG nVisibleColNo,
	LONG nVisibleRowNo,
	LONG nColNo,
	LONG nRowNo,
	const RECT & rcCellExtra,
	const RECT & rcCell,
	const RECT & rcVisibleRange,
	DWORD dwAreaFlags,
	DWORD dwHelperPaintFlags
	) const
	ASSERT_VALID( this );
	ASSERT( dc.GetSafeHdc() != NULL );
	ASSERT( nVisibleColNo >= 0 );
	ASSERT( nVisibleRowNo >= 0 );
	ASSERT( nColNo >= 0 );
	ASSERT( nRowNo >= 0 );

	if (SelectionGetForCellPainting( nColNo, nRowNo ))
		m_bIsSelected = true;
	CExtPPVW < CExtReportGridWnd >::OnGbwPaintCell(dc, nVisibleColNo, nVisibleRowNo, nColNo, nRowNo, rcCellExtra,
													rcCell, rcVisibleRange, dwAreaFlags, dwHelperPaintFlags);
	m_bIsSelected = false;
CMyGridWnd::OnSiwGetSysColor( int nIndex ) const
	if (m_bIsSelected && nIndex == COLOR_3DFACE)
		return RGB(210,230,230); // selected background

    return CExtGridWnd::OnSiwGetSysColor( nIndex );
This workaround intensifies the highlighting but has the effect that it is painting the WHOLE ROW, i.e. even BEFORE column 0.

Would there be a more elegant solution for this (or even the whole) problem?


Technical Support Jun 4, 2008 - 7:30 AM

The column before the zero column is the left outer column. There are four types of the outer cells:

You can check any of this styles in the dwAreaFlags parameter. Or you can use the following statement to determine whether the OnGbwPaintCell method is invoked for any outer cell:
if( ( dwAreaFlags & __EGBWA_OUTER_CELLS ) != 0 )

Technical Support Oct 15, 2007 - 8:42 AM

You should create a class derived from CExtGridWnd and override the OnSiwGetSysColor() virtual method like as follows

COLORREF CMyGridWnd::OnSiwGetSysColor( int nIndex ) const
    if( nIndex == COLOR_HIGHLIGHTTEXT )
        return RGB(255,255,255); // selected text
    if( nIndex == COLOR_HIGHLIGHT )
        return RGB(255,0,0); // selected background
    return CExtGridWnd::OnSiwGetSysColor( nIndex );
The grid control uses the system color indexes to get all colors. But it calls the OnSiwGetSysColor() virtual method instead of ::GetSysColor() (Win32 API). So this code changes the selected text and background colors to white and red.