如何对DataGridView的行进行编号? [英] How to number the rows of DataGridView?

查看:17
本文介绍了如何对DataGridView的行进行编号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何给 datagridView 的行编号?当我添加额外的行时,数字会增加吗?

How to number the rows of datagridView ? That when I add additional row the number increments ?

推荐答案

不如使用datagridview的RowPostPaint事件

Rather use RowPostPaint event of datagridview

void GridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
   this.GridView.Rows[e.RowIndex].Cells[0].Value 
    = (e.RowIndex + 1).ToString();
}

这篇关于如何对DataGridView的行进行编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆