码迷,mamicode.com
首页 > 其他好文 > 详细

gridView行号的显示

时间:2014-09-12 15:02:13      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:datagridview   style   color   io   os   使用   ar   for   sp   

我们在进行开发的时候,很多地方希望dataGridview或girdView显示行号,这里我来说一下两种的实现方法

在girdView中很简单很好实现,我在这里写一下代码,具体其他功能可以看其带的DEMO,

    private void dataGridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
     {
        if (e.Info.IsRowIndicator)
        {
            e.Info.DisplayText = Convert.ToString(e.RowHandle + 1);
         }
     }

我们再看一下vs自带的dataGridView中行号的实现方法

 

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

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

不过多解释了,如果需要拷贝即可使用,呵呵

gridView行号的显示

标签:datagridview   style   color   io   os   使用   ar   for   sp   

原文地址:http://www.cnblogs.com/NetPig/p/3968345.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!