Created
December 3, 2014 08:21
-
-
Save aindong/bd9a1652dab5134b0137 to your computer and use it in GitHub Desktop.
Listen for the enter key and move on the next column or row on datagridview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData) | |
{ | |
try | |
{ | |
int icolumn = dgvCart.CurrentCell.ColumnIndex; | |
int irow = dgvCart.CurrentCell.RowIndex; | |
if (keyData == Keys.Enter) | |
{ | |
if (icolumn == dgvCart.Columns.Count - 1) | |
{ | |
dgvCart.Rows.Add(); | |
dgvCart.CurrentCell = dgvCart[0, irow + 1]; | |
} | |
else | |
{ | |
dgvCart.CurrentCell = dgvCart[icolumn + 1, irow]; | |
} | |
return true; | |
} | |
else | |
{ | |
return base.ProcessCmdKey(ref msg, keyData); | |
} | |
} | |
catch (InvalidOperationException ex) | |
{ | |
return false; | |
} | |
catch(NullReferenceException ex) | |
{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment