dgContact.PreferredRowHeight = 30; //Datagrid 行的高度
for(int i = 0 ; i < this.dataGrid1.VisibleRowCount - 1 ; i ++)
{
//填充cell的边界色
e.Graphics.DrawRectangle(new Pen(Color.Red),dataGrid1.GetCellBounds(i,2));
//填充cell格的颜色
e.Graphics.FillRectangle(Brushes.Beige,dataGrid1.GetCellBounds(i,2));
}
private void dgContact_Paint(object sender, PaintEventArgs e)
{
DataGrid dg = (DataGrid)sender;
if (dg.DataSource != null)
{
if (dg.VisibleRowCount == 0) return;
Rectangle currRct;
int iRowCount = dg.VisibleRowCount;
string sText = "";
int nowY = 0;
for (int i = 0; i < iRowCount; i++)
{
currRct = (Rectangle)dg.GetCellBounds(i, 0);
nowY = currRct.Y + 2;
sText = string.Format(" {0}", i + 1);
e.Graphics.DrawString(sText, dg.Font, new SolidBrush(Color.Black), 10, nowY);
}
}
}
参考来源:http://topic.csdn.net/t/20060914/17/5022713.htmls
paint方法里面
int i ;
for (i = 0; i < dataGrid1.VisibleRowCount;i++){
string temp = dataGrid1[i,3].ToString() ;
e.Graphics.FillRectangle(Brushes.Red, dataGrid1.GetCellBounds(i, 3));
e.Graphics.DrawString(temp, dataGrid1.Font, Brushes.Black, dataGrid1.GetCellBounds(i, 3).Left + 2, dataGrid1.GetCellBounds(i, 3).Top + 2);
}