运行结果:
在鼠标不去点、使用滚动条的时候,程序运行正常,一行一行地更新;
Bug说明:
1、更新的时候,如果格子有一小块已经显示出来,滚动条不会动;
2、鼠标点击滚动条后,程序运行会有问题
提示错误的地方:
int CGridCtrl::GetRowHeight(int nRow) const{ASSERT(nRow >= 0 && nRow < m_nRows);if (nRow < 0 || nRow >= m_nRows)return -1;return m_arRowHeights[nRow];}
我的代码如下:
void CGridControlTest03Dlg::GridCtrlInit(){m_pGrid.SetEditable(true);m_pGrid.SetTextBkColor(RGB(0xFF, 0xFF, 0xE0));//黄色背景m_pGrid.SetRowCount(16); //初始为100行m_pGrid.SetColumnCount(26); //初始化为25列m_pGrid.SetFixedRowCount(1); //表头为一行m_pGrid.SetFixedColumnCount(1); //表头为一列for (int row = 0; row < m_pGrid.GetRowCount(); row++)for (int col = 0; col < m_pGrid.GetColumnCount(); col++){//设置表格显示属性GV_ITEM Item;Item.mask = GVIF_TEXT|GVIF_FORMAT;Item.row = row;Item.col = col;m_pGrid.SetRowHeight(row,25); //设置各行高m_pGrid.SetColumnWidth(0,64); //设置0列宽m_pGrid.SetColumnWidth(col,64); //设置各列宽if(row==0&&col==0) //第(0,0)格{Item.nFormat = DT_CENTER|DT_WORDBREAK;Item.strText.Format(_T("报表显示"),col);}else if (row < 1) //设置0行表头显示{Item.nFormat = DT_CENTER|DT_WORDBREAK;Item.strText.Format(_T(" 项目%d"),col);}else if (col < 1) //设置0列表头显示{if(row< m_pGrid.GetRowCount()){Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;Item.strText.Format(_T("第%d次"),row);}}else{Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;Item.strText.Format(_T(""),2);}m_pGrid.SetItem(&Item);}}
void CGridControlTest03Dlg::OnBnClickedAutofillbox(){// TODO: Add your control notification handler code hereint col;GV_ITEM Item;rowCnt++;if (rowCnt > m_pGrid.GetRowCount()){rowCnt = 1;TextTemp = (~TextTemp)&0x00ff;}Item.mask = GVIF_TEXT|GVIF_FORMAT;Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;for (col = 1; col < m_pGrid.GetColumnCount(); col++){Item.row = rowCnt;Item.col = col;//Item.strText.Format(_T("55"),rowCnt);Item.strText.Format(_T("%x"),TextTemp,rowCnt);m_pGrid.SetItem(&Item);}m_pGrid.Refresh();if (!m_pGrid.IsCellVisible(rowCnt, 1)){int scrollPos = m_pGrid.GetScrollPos32(SB_VERT);CCellID idTopLeft = m_pGrid.GetTopleftNonFixedCell();int yScroll = m_pGrid.GetRowHeight(idTopLeft.row);if (rowCnt == 1 && scrollPos > 0){scrollPos = 0;yScroll = 0;}m_pGrid.SetScrollPos32(SB_VERT, scrollPos + yScroll);}}