获取表格记录ID值

时间:2022-04-30 19:14:02

获取表格记录ID值

 

 

  private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //获取行首的单元格双击事件,并以此值作为传参对象

            //get id column index
           int IdcolumeIndex=0;
            foreach (DataGridViewTextBoxColumn item in this.dataGridView1.Columns)
            {
                if(item.Name.Equals("id"))
                {
                  IdcolumeIndex=  item.Index;
                }

            }

            object objCellValue = this.dataGridView1.Rows[e.RowIndex].Cells[IdcolumeIndex].Value;
         
            string s= objCellValue.ToString().Trim();
            MessageBox.Show(s);
            addrecord ar =                        new addrecord();
            ar.editid = Convert.ToInt32(s);
            ar.Show();
        }