DataGridView控件在显示数据时,我们有时候需要显示行号,以便检索查看方便使用。

但DataGridView默认没有设置显示行号的属性。

此时我们只要在DataGridView的RowPostPaint事件中进行绘制,实现其效果:

private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
SolidBrush b = new SolidBrush(this.dataGridView1.RowHeadersDefaultCellStyle.ForeColor);
e.Graphics.DrawString((e.RowIndex + ).ToString(System.Globalization.CultureInfo.CurrentUICulture), this.dataGridView1.DefaultCellStyle.Font, b, e.RowBounds.Location.X + , e.RowBounds.Location.Y + );
}

试试看!!

DataGridView显示行号-RowPostPaint的更多相关文章

  1. Winform中的DatagridView显示行号

    1.设置 RowPostPaint 为true 2.启用RowPostPaint事件 /// <summary> /// DataGridView显示行号 /// </summary ...

  2. DataGridView显示行号

    //可以在DataGirdView的RowPostPaint事件中进行绘制. //如:添加以下方法代码 private void DrawRowIndex(object sender, DataGri ...

  3. C# DataGridView显示行号的三种方法

    方法一: 网上最常见的做法是用DataGridView的RowPostPaint事件在RowHeaderCell中绘制行号: private void dgGrid_RowPostPaint( obj ...

  4. DataGridView显示行号的几种方法来自http://www.soaspx.com/dotnet/csharp/csharp_20100204_2740.html

    方法一: 网上最常见的做法是用DataGridView的RowPostPaint事件在RowHeaderCell中绘制行号: private void dataGridView1_RowPostPai ...

  5. 【转】DataGridView显示行号

    ref:http://blog.csdn.net/xieyufei/article/details/9769631 方法一: 网上最常见的做法是用DataGridView的RowPostPaint事件 ...

  6. 让DataGridView显示行号

          http://www.cnblogs.com/JuneZhang/archive/2011/11/21/2257630.html 为了表示行号,我们可以在DataGridView的RowP ...

  7. DataGridView 显示行号与背景颜色

    实现的方式有好几种.之前使用的是下面这种在RowPostPaint事件中实现,效率不高.每次改变控件尺寸时都会执行 private void MsgGridView_RowPostPaint(obje ...

  8. DataGridView大扩展——显示行号

    原文 DataGridView大扩展——显示行号 在DataGridView 的实际使用中,经常需要标示出行号,这样可以比较醒目地看到当前信息.不过DataGridView 在绘制 DataGridV ...

  9. DataGridView自动行号

    最近又用了一下DataGridView控件,需要显示行号,我们知道在.net中DataGridView控件默认是不显示行号(数据的记录行数)的,后来通过查资料发现可以在DataGridView控件的R ...

随机推荐

  1. Breaking Down Type Erasure in Swift

    Type Erasure Pattern We can use the type erasure pattern to combine both generic type parameters and ...

  2. moand的编程学形式:一个(高阶)类型包办程序的组织--类型关乎复合

    moand的编程学形式:一个(高阶)类型完成程序的组织. 将类型系统的转换与高阶函数进行了融合,相对于链式编程而言. 类型关乎复合 范畴论与箭头的复合有关.但是并非任意两个箭头都可以复合.一个箭头的目 ...

  3. Spring IOC 之 SmartInitializingSingleton

    使用 实现该接口后,当所有单例 bean 都初始化完成以后, 容器会回调该接口的方法 afterSingletonsInstantiated. 主要应用场合就是在所有单例 bean 创建完成之后,可以 ...

  4. Xcode 备忘

    一. 打印一堆乱七八糟的东西: Edit Scheme... --> Run --> Arguments,在 Environment Variables 里添加 OS_ACTIVITY_M ...

  5. html样式表格

    <html><body><table border="1">  <tr height="20px">    &l ...

  6. 自定义View之实现流行的底部菜单栏中间突起:高仿“咸鱼APP”的底部菜单 - z

    http://blog.csdn.net/xh870189248/article/details/75808341 http://blog.csdn.net/yangg194/article/deta ...

  7. 20155318 《网络攻防》 Exp7 网络欺诈防范

    20155318 <网络攻防> Exp7 网络欺诈防范 基础问题 通常在什么场景下容易受到DNS spoof攻击 DNS spoof攻击即执行DNS欺骗攻击,通过使用Ettercap来进行 ...

  8. python 回溯法 子集树模板 系列 —— 8、图的遍历

    问题 一个图: A --> B A --> C B --> C B --> D B --> E C --> A C --> D D --> C E -- ...

  9. PostgreSQL同步方案

    Windows下Postgre SQL数据库通过Slony-I实现数据库双机同步备份 - 数据库其他综合 - 红黑联盟 postgresql同步流复制的Hot Standby - CSDN博客   使 ...

  10. libgdx学习记录22——3d物体创建

    libgdx是一个强大的游戏框架,不仅支持2d部分,同时还支持3d部分. libgdx的3d部分投影主要通过PerspectiveCamera实现. 物体的显示过程: 1. 创建远景相机,角度一般设为 ...