开发者

DataGridView / Enter Key?

I'm using vb.net 2008 and DataGridView. I'm looking for code that will allow me to have the enter k开发者_开发知识库ey move to the next column to the right instead of moving down one row while remaining in the same column.


If you are confirming an edit, just move to the next column in the event CellEndEdit. If you are not in edit mode, you need to override ProcessDialogKey. See example below:

public class dgv : DataGridView
{
    protected override bool ProcessDialogKey(Keys keyData)
    {
        Keys key = (keyData & Keys.KeyCode);
        if (key == Keys.Enter)
        {
            return this.ProcessRightKey(keyData);
        }
        return base.ProcessDialogKey(keyData);
    }
    protected override bool ProcessDataGridViewKey(KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            return this.ProcessRightKey(e.KeyData);
        }
        return base.ProcessDataGridViewKey(e);
    }
}


Here's a CodeProject article that shows what you want to do:

Cheating the DataGridView

It's C# but it's also pretty simple.

The approached discussed in the article is to subclass the DataGridView to override the ProcessDialogKey event to handle the logic of selecting the next cell in the same row, or wrapping to first the column on the next row.

Most of the approaches for doing what you want to do seem to involve subclassing DataGridView.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜