我希望使用 //li[text()='DropdownValue']
和KeyUp
事件在datagridview中将所选值显示到文本字段
KeyDown
答案 0 :(得分:0)
如果您希望获得所选单元格的值,那么您需要的只是触发 DataGridView KeyDown事件并将代码编写为
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
txtName.Text = dataGridView1.CurrentCell.Value.ToString();
//do whatever you want to
}
}
如果你想获得整行并执行操作,你可以将其作为
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
int row = dataGridView1.CurrentCell.RowIndex;
txtID.Text = dataGridView1.Rows[row].Cells[0].Value.ToString();
txtName.Text = dataGridView1.Rows[row].Cells[1].Value.ToString();
//do whatever you want to
}
}