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 » Change background color in CExtGridCell Collapse All
Subject Author Date
Eric May 11, 2011 - 2:02 PM

Hello,


I’m using the CExtPropertyGridCtrl control. I would like to customize the background color of the cell that contains the property’s name(the left one). I can change the background color of the cell at the right(a checkbox) with BackColorSet, but I’d like to do the same with the cell at the left(the one with the property’s name). I need to be able to change the background color of any cell individually, at any time.


Thanks

Technical Support May 13, 2011 - 12:42 PM

Here is how to paint a red background for all cells:

bool CYourTreeGrid::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
{
    dc.FillSolidRect( &rcCell, RGB(255,0,0) );
    return false;
}

Here is how to paint red background for property values, green for categories:
bool CYourTreeGrid::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
{
HTREEITEM hti = ItemGetByVisibleRowIndex( nRowNo );
    ASSERT( hti != NULL );
CExtPropertyItem * pPI = PropertyItemFromTreeItem( hti );
    ASSERT( pPI != NULL );
    if( pPropertyItem->IsKindOf( RUNTIME_CLASS(CExtPropertyValue) ) )
        dc.FillSolidRect( &rcCell, RGB(255,0,0) );
    else if( pPropertyItem->IsKindOf( RUNTIME_CLASS(CExtPropertyCategory) ) )
        dc.FillSolidRect( &rcCell, RGB(0,255,0) );
    return false;
}
If this virtual method paints a custom background and returns false, the tree grid control assumes there is no custom background and paints only the selected background for selected tree rows. The normal background (not selected) is not painted: it is a white background of the tree grid control. If this virtual method returns true, the tree grid assumes your code is completely responsible for painting cell backgrounds.

Technical Support May 13, 2011 - 2:07 AM

Please override the CExtPropertyGridCtrl::OnPgcCreateGrids() virtual method. Your method should be similar to original but it should instantiate and create your tree grid classes. There are two tree grids. Please create your CExtPropertyGridWndCategorized-derived and CExtPropertyGridWndSorted-derived tree grid classes. They will be used by your property grid control. They are needed for providing particular tree rows with custom background color. Your tree grid controls should implement the CExtGridWnd::OnGridHookCellPaintBackground() virtual method and it should paint custom colored background for grid cells. This method has the nRowNo parameter which specifies plain zero based tree row index. The CExtTreeGridWnd::ItemGetByVisibleRowIndex() method can convert it into HTREEITEM tree row handle. The CExtPropertyGridWnd::PropertyItemFromTreeItem() method can the HTREEITEM tree row handle into the CExtPropertyItem * pointer that can be either CExtPropertyValue * or CExtPropertyCategory *. So, your overriden OnGridHookCellPaintBackground() method will always know which background it should paint. Please note, both tree grids always have two columns. Column with index 0 displays property value/category name. Column with index 1 displays active value of property value. The sorted tree grid does not display property categories. The property categories are displayed by categorized tree grid and their grid cells in column with index 0 are stretched horizontally to cover both columns.

Eric May 13, 2011 - 11:04 AM

Thanks for your answer


How are we supposed to use OnGridHookCellPaintBackground()? There is no doc on it and the Prof-UIS implementation looks like this:


bool CExtGridWnd::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
{
    __EXT_DEBUG_GRID_ASSERT_VALID( this );

_cell; dc; nVisibleColNo; nVisibleRowNo; nColNo; nRowNo; nColType; nRowType; rcCellExtra; rcCell; rcVisibleRange; dwAreaFlags; dwHelperPaintFlags;
return false;
}

I don’t understand this code... Where do we specify the custom color?