我正在尝试将 Gridviewer 中的数据显示到表单列,但每当我单击 DGV 中的一行时,我都会收到错误消息“索引超出范围。必须为非负数且小于集合参数名称的大小”
int Key = 0;
private void EmployessDGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
EmpNametbl.Text = EmployessDGV.SelectedRows[0].Cells[1].Value.ToString();
EmpPhoneTb.Text = EmployessDGV.SelectedRows[1].Cells[2].Value.ToString();
EmpAddTb.Text = EmployessDGV.SelectedRows[2].Cells[3].Value.ToString();
EmpPassTb.Text = EmployessDGV.SelectedRows[3].Cells[4].Value.ToString();
if (EmpNametbl.Text == "")
{
Key = 0;
}
else
{
Key = Convert.ToInt32(EmployessDGV.SelectedRows[0].Cells[0].Value.ToString());
}
}