光标移动到DataGridView中的下一个单元格

时间:2012-02-14 14:41:34

标签: c# .net datagridview

如果我在DataGridViewTextBoxCell中编辑DataGridView并按向右箭头移动到字符串的末尾,当我到达字符串的末尾时,光标将离开编辑模式DataGridViewTextBoxCell并选择旁边的DataGridViewTextBoxCell

这是默认行为吗?

有没有办法将插入符号/光标保留在当前正在编辑的DataGridViewTextBoxCell内?

1 个答案:

答案 0 :(得分:0)

    private bool dont_jump;
    private int col_index;
    private int row_index;

    private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
        dont_jump = true;
        col_index = e.ColumnIndex;
        row_index = e.RowIndex;
    }

    private void dataGridView1_SelectionChanged(object sender, EventArgs e)
    {
        if (dont_jump)
        {
            dont_jump= false;
            dataGridView1.CurrentCell = dataGridView1[col_index, row_index];
        }
    }

也许这对你有用