标签:
代码:
intCGridCtrl::GetRowHeight(int nRow)const
{
ASSERT(nRow >=0&& nRow < m_nRows);
if(nRow <0|| nRow >= m_nRows)
return-1;
return m_arRowHeights[nRow];
}
voidCGridControlTest03Dlg::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);
}
elseif(row <1)//设置0行表头显示
{
Item.nFormat = DT_CENTER|DT_WORDBREAK;
Item.strText.Format(_T(" 项目%d"),col);
}
elseif(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);
}
}
voidCGridControlTest03Dlg::OnBnClickedAutofillbox()
{
// TODO: Add your control notification handler code here
int 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);
}
}
GridCtrl学习笔记(3)一行一行地更新表格,有bug版
标签:
原文地址:http://www.cnblogs.com/ciuciu/p/4462788.html