灵魂-放水

为学日益,为道日损。

BlogJava 首页 新随笔 联系 聚合 管理
  296 Posts :: 10 Stories :: 274 Comments :: 0 Trackbacks
DataGridView控件的属性中,无法设置显示行号,为了达到如图所示的效果:



可以在DataGirdView的RowPostPaint事件中进行绘制。
如:添加以下方法代码

private void DrawRowIndex(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
               e.RowBounds.Location.Y,
               this.costomerDataGridView.RowHeadersWidth - 4,
               e.RowBounds.Height);

            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                this.costomerDataGridView.RowHeadersDefaultCellStyle.Font,
                rectangle,
                this.costomerDataGridView.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);

        }
即可完成显示行号的功能。

posted on 2007-01-27 11:23 放水老倌 阅读(3508) 评论(0)  编辑  收藏 所属分类: .NET

只有注册用户登录后才能发表评论。


网站导航: