CGXGridCore::SetViewID

void SetViewID(int nID);

nId

An integer value specifying the view id.

Remarks

Specifies a unique identifier for the type of view, useful when you have several different grid-views attached to a document.

Using different view-ids avoids unnecessary updating of different views. When the user changes a cell in grid-view type 1, it need not be updated in grid-view type 2.

Call EnableHints to enable the update hint mechanism.

Example

This example illustrates the usage of m_nViewID. The class CTableView which is derived from CGXGridView obtains its own view-id.

const nTableView = 1;
const nColumnView = 2;
CTableView::CTableView( )
{
   SetViewID(nTableView);
}

The next example illustrates how to use different types of grid-views with one document. CTableView displays the results of an SQL-Query, whereas CColumnView displays the column settings. CTableView and CColumnView have different view-ids.

When the user moves rows in CColumnView, in CTableView the columns have to be moved.

const UINT nMyHintMoveColumns = 101;
/////////////////////////////////////////////////////////////////
// CColumnView
// rows have been moved in CColumnView
void CColumnView::UpdateMoveRows(ROWCOL nFromRow, ROWCOL nToRow,
ROWCOL nDestRow, UINT flags, BOOL bCreateHint)
{
   CGXGridView::UpdateMoveRows(nFromRow, nToRow, nDestRow, flags, FALSE);
   if (bCreateHint)
   {
      CGXGridHint hint(nMyHintMoveColumns, GetViewID( ));
      hint.nRow1 = nFromRow;
      hint.nRow2 = nToRow;
      hint.nRow3 = nDestRow;
      hint.flags = flags;
      GetDocument( )->UpdateAllViews(this, 0, &hint);
   }
}
// interpret hint-object
void CColumnView::OnUpdate(CView* pSender, LPARAM lHint, CObject*
pHint)
{
   if (pHint->IsKindOf(RUNTIME_CLASS(CGXGridHint)))
   {
      switch (info.m_id)
      {
      case nMyHintMoveColumns:
         UpdateMoveRows(
            info.nRow1,
            info.nRow2,
            info.nRow3,
            info.flags,
            FALSE);
         return;
       }
       ....
   }
   CGXGridView::OnUpdate(pSender, lHint, pHint);
}
/////////////////////////////////////////////////////////////////
// CTableView
// Columns have been moved in CTableView
void CColumnView::UpdateMoveCols(ROWCOL nFromCol, ROWCOL nToCol,
ROWCOL nDestCol, UINT flags, BOOL bCreateHint)
{
   CGXGridView::UpdateMoveCols(nFromCol, nToCol, nDestCol, flags, FALSE);
   if (bCreateHint)
   {
      CGXGridHint hint(nMyHintMoveColumns, GetViewID( ));
      hint.nRow1 = nFromCol;
      hint.nRow2 = nToCol;
      hint.nRow3 = nDestCol;
      hint.flags = flags;
      GetDocument( )->UpdateAllViews(this, 0, &hint);
   }
}
// interpret hint-object
void CTableView::OnUpdate(CView* pSender, LPARAM lHint, CObject*
pHint)
{
   if (pHint->IsKindOf(RUNTIME_CLASS(CGXGridHint)))
   {
      switch (info.m_id)
      {
      case nMyHintMoveColumns:
         // Hier muessen die Spalten verschoben werden !
         UpdateMoveCols(
            info.nRow1,
            info.nRow2,
            info.nRow3,
            info.flags,
            FALSE);
         return;
       }
       ....
   }
   CGXGridView::OnUpdate(pSender, lHint, pHint);
}

See Also

 CGXGridView  CGXGridCore::EnableHints

CGXGridCore

 Class Overview |  Class Members