为了表示行号,我们可以在DataGridView的RowPostPaint事件中进行绘制。RowPostPaint事件,具体可以参照MSDN。

下面是实现代码:

private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)

        {
            System.Drawing.Rectangle rectangle = 
                new System.Drawing.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);

}

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

  1. Winform中的DatagridView显示行号

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

  2. DataGridView显示行号-RowPostPaint

    DataGridView控件在显示数据时,我们有时候需要显示行号,以便检索查看方便使用. 但DataGridView默认没有设置显示行号的属性. 此时我们只要在DataGridView的RowPost ...

  3. DataGridView显示行号

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

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

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

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

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

  6. 【转】DataGridView显示行号

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

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

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

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

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

  9. DataGridView自动行号

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

随机推荐

  1. 史上最全面的FRM与CFA的区别对比分析,适合新人看

    简单地自我介绍:本人于纽约完成了研究生阶段的学习后,在华尔街混迹了几年的时间,已获取FRM证书,正在积极准备CFA. 上海财经大学FRM培训中心前言导读 经常看到CFA持证人平均年收入为$XXX之类的 ...

  2. 中国海洋大学第四届朗讯杯高级组 Cash Cow(模拟)

    题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2721 题意: 给定n个左标,跟那n个坐标 ...

  3. poj3225 线段树区间操作 (见鬼)

    细节处理实在太重要了. #include<cstdio> #include<cstring> #define MT 65533*4 #define Maxn MT*4 int ...

  4. NOI2002robot

    这题又是纯数论题…… 独立数就是欧拉函数,政客和军人的含义已经说的很清楚了,学者是最多的…… 首先,如果我们知道了政客和军人的答案,那就只要用n的所有因子的欧拉函数值减去这两个值,然后取模就行了. 但 ...

  5. 三个流行MySQL分支的对比

    MySQL是历史上最受欢迎的免费开源程序之一.它是成千上万个网站的数据库骨干,并且可以将它(和Linux)作为过去10年里Internet呈指数级增长的一个有力证明. 那么,如果MySQL真的这么重要 ...

  6. Java [leetcode 37]Sudoku Solver

    题目描述: Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated ...

  7. 统一Matlab下不同子图的色标colorbar

    Reference:http://www.mathworks.com/matlabcentral/answers/100950-how-can-i-have-a-standard-colorbar-f ...

  8. Handler一定要在主线程实例化吗?new Handler()和new Handler(Looper.getMainLooper())的区别?

    一个帖子的整理: Handler一定要在主线程实例化吗?new Handler()和new Handler(Looper.getMainLooper())的区别如果你不带参数的实例化:Handler ...

  9. android ListView详解

    转自:http://www.cnblogs.com/allin/archive/2010/05/11/1732200.html 在android开发中ListView是比较常用的组件,它以列表的形式展 ...

  10. lightoj 1015

    水题,统计大于0的和. #include<cstdio> int main(){ int t, n, tmp; scanf("%d", &t); for(int ...