一,新建一个BCG对话框工程BCGPGridCtrlColorSingle。
二,CBCGPGridCtrlColorSingleDlg类增加变量。
CBCGPGridCtrl m_grid;
三,CBCGPGridCtrlColorSingleDlg::OnInitDialog中增加如下代码。
CRect r(0,0,300,300); m_grid.Create(WS_CHILD, r, this, 1); m_grid.ShowWindow(SW_SHOW); m_grid.InsertColumn (0, _T("A"), 40); m_grid.InsertColumn (1, _T("B"), 100); m_grid.InsertColumn (2, _T("A"), 40); m_grid.InsertColumn (3, _T("B"), 100); const int iCol = m_grid.GetColumnCount (); for( long i = 0 ; i < 29 ; i++ ) { CBCGPGridRow* pRow = m_grid.CreateRow (iCol); if( NULL == pRow ) return TRUE ; pRow->GetItem(0)->SetValue((long)(i/10)); for(long j = 1 ; j < iCol ; j++ ) { pRow->GetItem(j)->SetValue((long)((i+1)*(j+1))); } m_grid.AddRow (pRow, FALSE); pRow->GetItem(0)->SetTextColor(RGB(255,0,0)); } m_grid.AdjustLayout ();
四,Ctrl+F5查看运行效果。
五,增加按钮,并添加响应函数。效果是将第一行第一列,前景色变蓝,背景色变绿。
void CBCGPGridCtrlColorSingleDlg::OnButton1() { CBCGPGridRow* pRow = m_grid.GetRow(1); if( NULL == pRow ) return ; CBCGPGridItem* pItem = pRow->GetItem(1); if( NULL == pItem ) return ; pItem->SetTextColor(RGB(0,0,255)); pItem->SetBackgroundColor(RGB(0,255,0)); }
六,Ctrl+F5查看运行效果。
源码下载:
http://download.csdn.net/detail/he_zhidan/8009531