我定义了一个CGridCtrl* m_pGridCtrl;
然后在初始化中用该指针创建了一个表
    OnInitialUpdate() 
{
  m_pGridCtrl = new CGridCtrl;
  CRect rect;
  GetClientRect(rect);
  width=rect.right-rect.left;
  m_pGridCtrl->Create(rect, this, 100);
}
另外,我通过构造的表格指针m_pGridCtrl分别创建了五个表格,我想通过点击左边的树视图的相应相,右边能出现不同的表格,但问题在于表格怎样刷新。即点击后一个表格,前一个建立的表格对它有影响。
马上快毕业了,可程序还没着落,希望高手能出来指导。
回答正确了另外给分

解决方案 »

  1.   

    可能我没说清楚。
    具体程序如下
    void CReportView::OnInitialUpdate() 
    {
    CView::OnInitialUpdate();

    // TODO: Add your specialized code here and/or call the base class
    if (m_pGridCtrl == NULL)
    {
    // 创建 Gridctrl 对象
    m_pGridCtrl = new CGridCtrl;
    if (!m_pGridCtrl) return; // 创建 Gridctrl 窗口
    CRect rect;
    GetClientRect(rect);
    width=rect.right-rect.left;
    m_pGridCtrl->Create(rect, this, 100);
    }
    }
    void CReportView::DrawDeviationGrid()//电压偏差报表
    {
        CDC* pDC;
    if (m_pGridCtrl != NULL)
    {
    try 
    {
    m_pGridCtrl->SetRowCount(62);//还需修改
    m_pGridCtrl->SetColumnCount(4);
    m_pGridCtrl->SetFixedRowCount(1);
    m_pGridCtrl->SetFixedColumnCount(1);
    }
    catch (CMemoryException* e)
    {
    e->ReportError();
    e->Delete();
    return;
    }

    pDC=m_pGridCtrl->GetDC();
            GV_ITEM Item;
    CSize cellSize;
    // 填充每格数据
    for (int row = 0; row < m_pGridCtrl->GetRowCount(); row++)
    for (int col = 0; col < m_pGridCtrl->GetColumnCount(); col++)


    Item.mask = GVIF_TEXT|GVIF_FORMAT;
    Item.row = row;
    Item.col = col;
    Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;

        if(row<1)
    {

    switch(col)
    {
      case 0:
      Item.szText.Format(_T("记录号"));
      cellSize=pDC->GetTextExtent("记录号");
          m_pGridCtrl->SetColumnWidth(Item.col,cellSize.cx+10);
      break;
                          case 1:Item.szText.Format(_T("时间"));break;
      case 2:Item.szText.Format(_T("频率偏差"));break;
      case 3:Item.szText.Format(_T("电压偏差"));break;
    }
    if(col>0)m_pGridCtrl->SetColumnWidth(Item.col,(width-cellSize.cx-10)/2);
    }
       else 
       {
      Item.szText.Format(_T(""));
       }
    m_pGridCtrl->SetItem(&Item);
    }
          m_pGridCtrl->SetRowHeight(0, 3*m_pGridCtrl->GetRowHeight(0)/2);
    }
    ReleaseDC(pDC); 

    }
    void CReportView::DrawFluctuateandFlickerGrid()//波动与闪变报表  
    {
        CDC* pDC;
    if (m_pGridCtrl != NULL)
    {
       try 
    {
    m_pGridCtrl->SetRowCount(62);//还需修改
    m_pGridCtrl->SetColumnCount(6);
    m_pGridCtrl->SetFixedRowCount(1);
    m_pGridCtrl->SetFixedColumnCount(1);
    }
    catch (CMemoryException* e)
    {
    e->ReportError();
    e->Delete();
    return;
    }

    pDC=m_pGridCtrl->GetDC();
            GV_ITEM Item;
    CSize cellSize;
    // 填充每格数据
    for (int row = 0; row < m_pGridCtrl->GetRowCount(); row++)
    for (int col = 0; col < m_pGridCtrl->GetColumnCount(); col++)


    Item.mask = GVIF_TEXT|GVIF_FORMAT;
    Item.row = row;
    Item.col = col;
    Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;

        if(row<1)
    {

    switch(col)
    {
      case 0:
      Item.szText.Format(_T("记录号"));
      cellSize=pDC->GetTextExtent("记录号");
          m_pGridCtrl->SetColumnWidth(Item.col,cellSize.cx+20);
      break;
                          case 1:Item.szText.Format(_T("时间"));break;
      case 2:Item.szText.Format(_T("瞬时闪变视感度"));break;
      case 3:Item.szText.Format(_T("短时闪变视感度"));break;
      case 4:Item.szText.Format(_T("等效闪变值"));break;
      case 5:Item.szText.Format(_T("电压波动值"));break;
    }
    if(col>0)m_pGridCtrl->SetColumnWidth(Item.col,(width-cellSize.cx+20)/4);
    }
       else 
       {
      Item.szText.Format(_T(""));
       }
    m_pGridCtrl->SetItem(&Item);
    } m_pGridCtrl->SetRowHeight(0, 3*m_pGridCtrl->GetRowHeight(0)/2);
    }
    ReleaseDC(pDC);
    }
    我想点击不同的表时,这两表能相互切换,但一个表建立后,应该清除前一个表才能再建另一个
    我不知道该怎么清除,望高手请教。(回答正确另加100分)