How can I transfer data between the grid and the document when I am using other views (e.g. a hierarchy chart) and need to update all view when a cell value has changed?
a) You should override StoreStyleRowCol( ) and store the style's value in your document.
BOOL CSampleView::StoreStyleRowCol(ROWCOL nRow, ROWCOL nCol, const CGXStyle* pStyle, GXModifyType mt, int nType)
{
if (mt == gxRemove) // not supported
return FALSE;
// Note: Do not distinguish between gxApplyNew,
// gxCopy and gxOverride
if (nRow > 0 && nCol > 0 && nType == 0)
{
GetDocument( )->StoreCellValue(nRow, nCol, style.GetValueRef( ));
}
return CMyGridView::StoreStyleRowCol(nRow, nCol, pStyle, mt, nType);
}
b) You should override GetStyleRowCol( ) to retrieve the style's value from you doc:
BOOL CSampleView::GetStyleRowCol(ROWCOL nRow, ROWCOL nCol, CGXStyle& style, GXModifyType mt, int nType)
{
BOOL b = CMyGridView::GetStyleRowCol(nRow, nCol, style, mt, nType);
// Note: Do not distinct between gxApplyNew,
// gxCopy and gxOverride
if (nRow > 0 && nCol > 0 && nType == 0 && mt != gxRemove)
{
style.SetValue(GetDocument( )->GetCellValue(nRow, nCol);
}
return b;
}
c) In your other view's OnUpdate( ) method, you should update the view when you get a CGXGridHint object, with hint-id gxHintUpdateStyleRange:
void CMyOtherView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
if (pHint != NULL &&
pHint->IsKindOf(RUNTIME_CLASS(CGXGridHint)))
{
CGXGridHint &info = *((CGXGridHint*) pHint);
switch (info.nId)
{
case gxHintUpdateStyleRange:
case gxRedraw:
Invalidate( );
break;
}
}
}