网上找了几种显示行号的方法,采用了其中一种,在行头显示行号,很实用,如图:

为Winform程序中DataGridView控件增加自动显示行号功能

代码如下:

private void gvTransferList_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, gvTransferList.RowHeadersWidth, e.RowBounds.Height);
            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                gvTransferList.RowHeadersDefaultCellStyle.Font, rectangle, gvTransferList.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }

相关文章:

  • 2021-10-09
  • 2022-02-06
  • 2022-12-23
  • 2021-12-09
  • 2022-01-02
  • 2021-07-31
  • 2021-12-22
猜你喜欢
  • 2022-01-07
  • 2021-12-20
  • 2022-01-16
  • 2021-05-30
  • 2022-01-07
  • 2022-12-23
相关资源
相似解决方案