获取表格记录ID值

获取表格记录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();
        }

你可能感兴趣的:(表格,记录,private)