单击单元格任意地方事件

当我们在进行修改的时候,点击数据行,数据则会自动传送到相应的文本框中如图所示单击单元格任意地方事件

 

 

  1. //单击单元格任意地方事件
  2.         private void dgv_view_CellClick(object sender, DataGridViewCellEventArgs e)
  3.         {
  4.             int rowIndex = this.dgv_view.CurrentCell.RowIndex;
  5.             if (rowIndex > -1)
  6.             {
  7.                 if (this.dgv_view[0, rowIndex].Value.ToString() != string.Empty)
  8.                 {
  9.                      stu_id = Convert.ToInt32(this.dgv_view[0, rowIndex].Value.ToString());
  10.                     this.txt_name.Text = this.dgv_view[1, rowIndex].Value.ToString();
  11.                     this.txt_age.Text = this.dgv_view[2, rowIndex].Value.ToString();
  12.                     if (this.dgv_view[4, rowIndex].Value.ToString() == "男")
  13.                         this.rdo_man.Checked = true;
  14.                     else
  15.                         this.rdo_gdenman.Checked = true;
  16.                     this.cbo_class.Text = this.dgv_view[3, rowIndex].Value.ToString();
  17.                     this.txt_address.Text = this.dgv_view[5, rowIndex].Value.ToString();
  18.                 }
  19.                 else
  20.                 {
  21.                     MessageBox.Show("请选择数据行!");
  22.                     return;
  23.                 }
  24.             }
  25.         }

你可能感兴趣的:(事件)