无法在datagridview中选择下一行

时间:2014-03-03 11:22:39

标签: c# visual-studio datagridview keydown

这是我的代码:

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        button4.PerformClick();
    }
    else if (e.KeyCode == Keys.Add)
    {
        int R = dataGridView1.CurrentCell.RowIndex;
        R++;
        dataGridView1.Rows.Insert(R, textBox1.Text, pictureBox1.Image, pictureBox3.Image, pictureBox6.Image, label2.Text);
        itemPhrase();

        dataGridView1.EndEdit();
        dataGridView1.CancelEdit();
        dataGridView1.Rows[R].Selected = true;
        dataGridView1.Focus();
    }
}

这只选择我想要的行,但我不能编辑它,

enter image description here

它会改变它之前的行。

enter image description here

那么如何编辑我选择的行?

1 个答案:

答案 0 :(得分:0)

dataGridView1.CurrentCell = dataGridView1.Rows [g2] .Cells [0];