@Shaifalijee , Welcome to Microsoft Q&A,I make the following example to explain these two methods.
public class NewDataGridView:DataGridView
{
protected override bool ProcessDialogKey(Keys keyData)
{
// Extract the key code from the key value.
Keys key = (keyData & Keys.KeyCode);
// Handle the ENTER key as if it were a RIGHT ARROW key.
if (key == Keys.Enter||key==Keys.Right)
{
Console.WriteLine("in edit");
return this.ProcessTabKey(keyData);
}
return base.ProcessDialogKey(keyData);
}
protected override bool ProcessDataGridViewKey(KeyEventArgs e)
{
// Handle the ENTER key as if it were a RIGHT ARROW key.
if (e.KeyCode == Keys.Enter)
{
Console.WriteLine("no edit");
return this.ProcessTabKey(e.KeyData);
}
return base.ProcessDataGridViewKey(e);
}
}
I override the two methods in the newdatagirdview control.
These two methods could achieve other key's functions both. For example, the following code could achieve tabkey's function when we press enter key or right key.
if (key == Keys.Enter||key==Keys.Right)
{
Console.WriteLine("in edit");
return this.ProcessTabKey(keyData);
}
The difference between them is that the control should be in edit mode when we want to use the key in the ProcessDialogKey method, and the control should not be in edit mode when we want to use the key in the ProcessDataGridViewKey method.
Hope my explanation could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.