網上最常見的做法是用DataGridView的RowPostPaint事件在RowHeaderCell中繪制行號:
privatevoiddataGridView1_RowPostPaint(objectsender, DataGridViewRowPostPaintEventArgs e)
{
try
{
e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, new SolidBrush(Color.CadetBlue), e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
}
catch(Exception ex)
{
MessageBox.Show("添加行號時發生錯誤,錯誤信息:"+ex.Message, "操作失敗");
}
}
但是這種方法在大數據量的時候性能比較差,每次滾動數據都會觸發RowPostPaint事件。
posted on 2012-12-11 14:54
Ke 閱讀(2296)
評論(1) 編輯 收藏 所屬分類:
C#