To set custom tooltip text for the cell, you can also override the CExtGridCell::OnInitToolTip
virtual method in the cell class.
Your CExtGridCell (or any other)
derived class may look like:
DECLARATION
class CExtGridCellTooltip : public CExtGridCell
{
public:
DECLARE_SERIAL( CExtGridCellTooltip );
IMPLEMENT_ExtGridCell_Clone( CExtGridCellTooltip, CExtGridCell );
CExtGridCellTooltip(
CExtGridDataProvider * pDataProvider = NULL
);
// virtual methods
virtual bool OnInitToolTip(
CExtGridWnd & wndGrid,
const CExtGridHitTestInfo & htInfo,
CToolTipCtrl & wndToolTip,
UINT nToolNo,
const RECT & rcTool
);
}; // class CExtGridCellTooltip
IMPLEMENTATION
/////////////////////////////////////////////////////////////////////////////
// CExtGridCellTooltip
IMPLEMENT_SERIAL( CExtGridCellTooltip, CExtGridCell, VERSIONABLE_SCHEMA|1 );
CExtGridCellTooltip::CExtGridCellTooltip(
CExtGridDataProvider * pDataProvider // = NULL
)
: CExtGridCell ( pDataProvider )
{
}
bool CExtGridCellTooltip::OnInitToolTip(
CExtGridWnd & wndGrid,
const CExtGridHitTestInfo & htInfo,
CToolTipCtrl & wndToolTip,
UINT nToolNo,
const RECT & rcTool
)
{
ASSERT_VALID( this );
ASSERT_VALID( (&wndGrid) );
ASSERT( ! htInfo.IsHoverEmpty() );
ASSERT( htInfo.IsValidRect() );
htInfo;
bool bRetVal = false;
CExtSafeString strText( _T("Tooltip Text") );
if( strText.GetLength() > 0 )
{
wndToolTip.AddTool(
&wndGrid,
(LPCTSTR)strText,
&rcTool,
nToolNo
);
bRetVal = true;
}
if( ! bRetVal )
{
wndToolTip.DelTool( &wndGrid, nToolNo );
CWnd::CancelToolTips();
} // if( ! bRetVal )
return bRetVal;
}
To use this class use the following code:
CExtGridCellTooltip * pCellTooltip =
STATIC_DOWNCAST(
CExtGridCellTooltip,
m_wndGrid.GridCellGet(
4,
nRowNo,
0,
0,
RUNTIME_CLASS(CExtGridCellTooltip)
)
);
Please note you should disable the content pop-up window for grid cells. Such a tooltip-like window shows the cell content for a cell which is partially visible
m_wndGrid.EnableTooltips(
true,
true,
true,
true,
true
);
m_wndGrid.EnableExpanding(
false,
false,
false,
false,
false
);