写一个类继承DataGridView,重写OnKeyPress方法
 public class DataGridViewEx : DataGridView
 {
        protected override void OnKeyPress(KeyPressEventArgs e)
       {
            base.OnKeyPress(e);            if (this.CurrentCell == null || this.CurrentCell.RowIndex < 0 | this.CurrentCell.ColumnIndex < 0) return;            if (e.KeyChar == (char)Keys.Enter) {
                OnCellEndEdit(new DataGridViewCellEventArgs(this.CurrentCell.ColumnIndex, this.CurrentCell.RowIndex));
            }
        }}