Application Development

Software technique, Skills & Applications

DataGridView显示行号 May 14, 2007

Filed under: .Net C# VB.Net — meetme @ 1:36 am

可以在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);

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

 

Leave a Reply