DevExpress中gridView行号的显示

 

我们在进行开发的时候,很多地方希望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);
        }

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

posted on 2012-11-05 15:31  星空夜夏梦  阅读(305)  评论(0编辑  收藏  举报

导航