datagridview 数据处理方法 修改 删除 添加 下拉类表 弹出窗口
}
//采用弹出窗口方式,进行数据修改
DataGridView dgv = dataGridView1;
if (dgv.Rows[selectrowindex].Cells[1].Value != null)
{
//输入参数
string id = dgv.Rows[selectrowindex].Cells[0].Value.ToString();
string user_id = dgv.Rows[selectrowindex].Cells[1].Value.ToString(); string user_password =
dgv.Rows[selectrowindex].Cells[2].Value.ToString();
string user_class =
dgv.Rows[selectrowindex].Cells[3].Value.ToString();
string user_name =
dgv.Rows[selectrowindex].Cells[4].Value.ToString(); string user_sex =
dgv.Rows[selectrowindex].Cells[5].Value.ToString();
string outUserid, outUserpassword, outUserclass, outUsername, outUsersex; //输出参数
DialogResult myresult; //返回弹出窗口关闭状态
this.ShowDialogForm(id, user_id, user_password, user_class, user_name, user_sex, out outUserid, out outUserpassword, out outUserclass, out outUsername, out outUsersex, out myresult);
//如果修改了数据,把当前datagridview内容的对应值进行修改
if (myresult == DialogResult.OK)
{
dgv.Rows[selectrowindex].Cells[1].Value = outUserid;
dgv.Rows[selectrowindex].Cells[2].Value = outUserpassword; dgv.Rows[selectrowindex].Cells[3].Value = outUserclass; dgv.Rows[selectrowindex].Cells[4].Value = outUsername;
dgv.Rows[selectrowindex].Cells[5].Value = outUsersex;
}
}
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) {