English 中文(简体)
DataGridView / Enter Key?
原标题:

I m using vb.net 2008 and DataGridView. I m looking for code that will allow me to have the enter key move to the next column to the right instead of moving down one row while remaining in the same column.

最佳回答

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.

问题回答

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);
    }
}




相关问题
DataGridView / Enter Key?

I m using vb.net 2008 and DataGridView. I m looking for code that will allow me to have the enter key move to the next column to the right instead of moving down one row while remaining in the same ...

Disable Cell Highlighting in a datagridview

How to disable Cell Highlighting in a datagridview, Highlighting should not happen even if I click on the cell. Any thoughts please

Saving nested XML in C#

I ve go the following XML file... <A> <B> <C>ValueX</C> <D>ValueY</D> </B> </A> Which I read into a DataSet to display it in a ...

How to sort databound DataGridView column?

I know that there are a lot of questions on this topic. I have been through all of them but nothing seems to help. How to sort by clicking on column header? How should I modify this code to do the ...

热门标签