views:

250

answers:

2

In vb.net datagridview the default Enter/Return key behavior is to move to the next row is there a quick and easy way to avoid that.

Any suggestions are welcome

+4  A: 

You can try something like this in the gridview key down event

Private Sub DataGridView1_Keydown (...) Handlers DataGridView1.KeyDown
   If e.KeyCode = Keys.Enter Then
       ' Your code here
       e.SuppessKeyPress = True
  End If 
End Sub

Another option would be to create a custom grid view control

DataGridView.ProcessDataGridViewKey Method

astander
It works like Charm
Ramji
+1 This is what I needed. Thanks
gyurisc
+1  A: 

Override the DataGridView (write your own that inherits from it), and process the OnKeyDown method.

public partial class UserControl1 : DataGridView
{
    public UserControl1()
    {
        InitializeComponent();
    }

    protected override void OnKeyDown(KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
            return;

        base.OnKeyDown(e);
    }
}
slugster