Live Chat Icon For mobile
Live Chat Icon

How can I make the Enter Key behave like the Tab Key and move to the next cell

Platform: WinForms| Category: Datagrid

You can override ProcessCmdKey, catch the Enter Key, and swap it for a Tab key by sending a Tab, and not processing the Enter Key.

[C#]
	public class MyDataGrid : DataGrid
	{
		protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
		{
			if(msg.WParam.ToInt32() == (int) Keys.Enter)
			{
				SendKeys.Send('{Tab}');
				return true;
			}
			return base.ProcessCmdKey(ref msg, keyData);
		}
	}


[VB.NET]
	Public Class MyDataGrid
		Inherits DataGrid
     
		Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, keyData As System.Windows.Forms.Keys) As Boolean
			If msg.WParam.ToInt32() = CInt(Keys.Enter) Then
				SendKeys.Send('{Tab}')
				Return True
			End If
			Return MyBase.ProcessCmdKey(msg, keyData)
		End Function ’ProcessCmdKey

	End Class ’MyDataGrid

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.