现在的位置: 首页 > 综合 > 正文

winform c# datagridview 添加序号列

2013年07月20日 ⁄ 综合 ⁄ 共 290字 ⁄ 字号 评论关闭

1.在datagridview中增加一空列放在最前面

2.添加事件代码:

       private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                row.Cells[0].Value = row.Index+1;
            }
        }

(更改查询结果后序号可自动重新排列!)

抱歉!评论已关闭.