当我们在进行修改的时候,点击数据行,数据则会自动传送到相应的文本框中如图所示
- //单击单元格任意地方事件
- private void dgv_view_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- int rowIndex = this.dgv_view.CurrentCell.RowIndex;
- if (rowIndex > -1)
- {
- if (this.dgv_view[0, rowIndex].Value.ToString() != string.Empty)
- {
- stu_id = Convert.ToInt32(this.dgv_view[0, rowIndex].Value.ToString());
- this.txt_name.Text = this.dgv_view[1, rowIndex].Value.ToString();
- this.txt_age.Text = this.dgv_view[2, rowIndex].Value.ToString();
- if (this.dgv_view[4, rowIndex].Value.ToString() == "男")
- this.rdo_man.Checked = true;
- else
- this.rdo_gdenman.Checked = true;
- this.cbo_class.Text = this.dgv_view[3, rowIndex].Value.ToString();
- this.txt_address.Text = this.dgv_view[5, rowIndex].Value.ToString();
- }
- else
- {
- MessageBox.Show("请选择数据行!");
- return;
- }
- }
- }