您的位置:首页 > 其它

为datagridView添加行号

2008-07-04 17:12 309 查看
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)

{

Color color = dataGridView1.RowHeadersDefaultCellStyle.ForeColor;

if (dataGridView1.Rows[e.RowIndex].Selected)

color = dataGridView1.RowHeadersDefaultCellStyle.SelectionForeColor;

else

color = dataGridView1.RowHeadersDefaultCellStyle.ForeColor;

using (SolidBrush b = new SolidBrush(color))

{

e.Graphics.DrawString((e.RowIndex+1).ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X+20, e.RowBounds.Location.Y+6);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: