如何获取DataGridView当前行的id号

来源:互联网 发布:linux下安装navicat 编辑:程序博客网 时间:2024/05/17 18:45

前提是,必须让数据库中的id号显示在表格中,(当然你可以显示后再隐藏掉)

如何获取当前选中的行的id呢?假设第一列就是id值

方法是:

dataGridView1.SelectedRows[0].Cells[0].Value.ToString()  进而用int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString())

或者:Convert.ToInt32(this.dgvUser.CurrentRow.Cells[0].Value.ToString())

label9.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();

原创粉丝点击