最近又用了一下DataGridView控件,需要显示行号,我们知道在.net中DataGridView控件默认是不显示行号(数据的记录行数)的,后来通过查资料发现可以在DataGridView控件的RowPostPaint事件里面写代码就可以了,具体例子如下:

private void MaindataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
                e.RowBounds.Location.Y,
                MaindataGridView.RowHeadersWidth,
                e.RowBounds.Height);

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

最新文章

  1. thinkphp3.22 多项目配置
  2. 将Mininet与真实网络相连接
  3. Kooboo CMS 介绍
  4. [Swust OJ 249]--凸包面积
  5. CSharp SQLServer 登陆
  6. 持续集成环境(Hudson)搭建
  7. css text-indent:999em
  8. BootLoader--改进(基于2440)
  9. 2#第一个Java程序
  10. Webpack学习-工作原理(上)
  11. ubunut下使用kubeadm离线安装k8s1.9
  12. BOM - 浏览器API
  13. java.lang.ClassNotFoundException: org.thymeleaf.spring5.view.ThymeleafViewRe。。。。。。。。。。。
  14. 微信小程序中用setData修改一个对象的属性值
  15. DRBD 实验
  16. Python教程 深入条件控制
  17. plsql 永久注册码
  18. 【51nod】1244 莫比乌斯函数之和
  19. TP框架项目部署linux大小写问题
  20. 3: 组件间的依赖管理 Managing Dependencies Between Components Using the Prism Library 5.0 for WPF(英汉对照版)

热门文章

  1. [置顶] c++类的继承(inheritance)
  2. PullToRefresh的个性化扩展
  3. Spring AOP (Spring 3.x 企业应用开发实战读书笔记第六章)
  4. .net 文件操作
  5. NDIS小鱼防火墙之拦截指定QQ登录
  6. 12天学好C语言——记录我的C语言学习之路(Day 4)
  7. jquery之each
  8. 轮子来袭 vJine.Core Orm 之 02_代码生成
  9. MongoDB的timezone问题
  10. memcached全面剖析--4