黑马程序员技术交流社区

标题: winform中datagridView的表头要不提供排序,该如何实现? [打印本页]

作者: hongiqnglik    时间: 2013-8-13 23:17
标题: winform中datagridView的表头要不提供排序,该如何实现?
winform中datagridView的表头要不提供排序,该如何实现?
作者: 咖喱猫    时间: 2013-8-13 23:23
本帖最后由 咖喱猫 于 2013-8-13 23:27 编辑

不知道是不是你想要的效果:
想要让DataGridView的左边列自动显示数字,需要在DataGridView的RowPostPant事件里面写上如图代码就会自动显示数字。
  1. {
  2.             System.Drawing.Rectangle rectangle =
  3.                 new System.Drawing.Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dataGridView1.RowHeadersWidth - 4, e.RowBounds.Height);
  4.             TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
  5.                 dataGridView1.RowHeadersDefaultCellStyle.Font, rectangle, dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
  6.                 TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
  7. }
复制代码

DataGridView左边默认第一列显示数字.png (4.73 KB, 下载次数: 7)

DataGridView左边默认第一列显示数字.png





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2