如何在datagridview vb.net中关注单元格

时间:2017-11-12 08:28:47

标签: c# asp.net vb.net visual-studio

事件:DataGridView1_CellEndEdit

    DataGridView1.CurrentCell = DataGridView1.Rows(e.RowIndex).Cells(2)
    DataGridView1.BeginEdit(True)

我想将第0行第2列的重点放在编辑

我编辑单元格并输入。 datagridview焦点第0行第2列 我输入它不是焦点第0行第2列 它专注于第1行第2列

此代码无效。

抱歉。我的英语不太好。谢谢。

我编辑单元格并输入:

enter image description here

datagridview焦点第0行第2列:

enter image description here

它关注第1行第2列:

enter image description here

1 个答案:

答案 0 :(得分:0)

我从您的问题中了解到,当您按cell键时,您希望转到datagridview Enter的下一个private void dataGridView1_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { e.SuppressKeyPress = true; int iColumn = dataGridView1.CurrentCell.ColumnIndex; int iRow = dataGridView1.CurrentCell.RowIndex; if (iColumn == dataGridView1.Columns.Count - 1) dataGridView1.CurrentCell = dataGridView1[0, iRow + 1]; else dataGridView1.CurrentCell = dataGridView1[iColumn + 1, iRow]; } } catch { } } private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == dataGridView1.Columns.Count - 1) { dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.CurrentRow.Index + 1].Cells[0]; } else { SendKeys.Send("{UP}"); SendKeys.Send("{left}"); } } 。试试这个

\"%{cache-status}e\"