You can do this using the following code
CExtReportGridWnd & wndRG = . . .
CExtReportGridColumn * pRGC = . . .
CExtReportGridItem & pRGI = . . .
if( pRGC == NULL || pRGC == NULL )
return ... // incorrect parameters
ASSERT_VALID( pRGC );
ASSERT_VALID( pRGI );
if( ! pRGC->ColumnIsActive() )
return . . . // it’s not possible to get cell rectangles if it’s inside inactive column
LONG nRowNo = wndRG.ItemGetVisibleIndexOf( (HTREEITEM)pRGI );
if( nRowNo < 0L )
return . . . // report row is collapsed and locations of its cells are unavailable
LONG nColNo = 0L, nTmp = wndRG.ColumnCountGet();
for( ; nColNo < nTmp; nColNo++ )
{
CExtGridCell * pHdrCell = wndRG.GridCellGetOuterAtTop( nColNo, 0L );
ASSERT_VALID( pHdrCell );
if( LPVOID(pHdrCell) == LPVOID(pRGC) )
break;
}
ASSERT( nColNo < nTmp );
CRect rcCell, rcCellExtra;
if( ! wndRG.GridCellRectsGet(
nColNo,
nRowNo,
0,
0,
&rcCell,
&rcCellExtra
)
)
return . . . // cell is outside visible range and its location is unavailable
As you can see, it’s not possible to get cell location if it’s inside an inactive column under a collapsed group row or not at least partially visible in the displayed cell range (you need to scroll to it). The computed
nColNo
and
nRowNo
indices can be used in invocations of the
CExtGridWnd::EnsureVisibleColumn()
and
CExtGridWnd::EnsureVisibleRow()
methods if you want to scroll the report grid to a particular cell. The
CExtGridWnd::GridCellRectsGet()
method can compute rectangles of all cell parts. In the code above we computed the
rcCell
rectangle of exact cell location. The
rcCellExtra
rectangle is exactly the same if auto-preview mode is off. If it’s on, then
rcCellExtra
rectangle contains a larger bottom side which is used by the in-row preview area.