首页 >> 文档 >> ASP.NET专题

为DataGridView添加行号

发布日期:2008-07-04最近更新:2008-07-04来源:BHCODE作者:

以下是DataGridView添加行号的代码:

 private void dgv1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)

        {

            try

            {

                Rectangle rectangle = new Rectangle(e.RowBounds.Location.X ,

                    Convert.ToInt32( e.RowBounds.Location.Y + (e.RowBounds.Height - dgv1.RowHeadersDefaultCellStyle.Font.Size) / 2),

                    dgv1.RowHeadersWidth - 4, e.RowBounds.Height);

                TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),

                    dgv1.RowHeadersDefaultCellStyle.Font, rectangle, dgv1.RowHeadersDefaultCellStyle.ForeColor,

                    TextFormatFlags.Right);

 

            }

            catch (Exception ex)

            {

                Console.Write("dgv1_RowPostPaint:" + ex.Message);

            }

        }

本周推荐
MORE
热点关注
MORE