zoukankan      html  css  js  c++  java
  • 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);
            }

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

  • 相关阅读:
    L7-5 搞笑的表情包
    L7-6 神奇的验证码
    Fabric中的ACLs相关
    first-network
    关于MSP
    关于数字证书
    Linux命令学习笔记
    shell学习笔记
    区块链
    log的不同级别
  • 原文地址:https://www.cnblogs.com/NetPig/p/3968345.html
Copyright © 2011-2022 走看看