protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.End) { DialogResult TheResult = MessageBox.Show(this, "Have you Finished Entering Details", "Confirmation", MessageBoxButtons.YesNo); if (TheResult == System.Windows.Forms.DialogResult.Yes) { if (objCollec.Count > 0) { DeliverNoteMaterials_DL objDeliverNoteMaterials_DL = new DeliverNoteMaterials_DL(ConnectionStringClass.GetConnection()); DeliverNote obj = new DeliverNote(); obj.DeleveryNoteID = txtDeliverNote.Text; obj.DeleveryNoteEnterdBy = objEmployee_DL.Get(CurrentUser.EmployeeID); obj.DeleveryNoteStatus = DeliverNote.Status.Initial; obj.DeleveryNoteDate = DateTime.Today; obj.DeleveryNotePO = "N/A"; obj.Remarks = txtRemarks.Text; obj.Supplier = Convert.ToInt64(txtSupplierCode.Text); objDeliverNote_DL.Add(obj); foreach (DeliverNoteMaterials tmpobj in objCollec) { tmpobj.DeliverNote = obj.DeleveryNoteID; objDeliverNoteMaterials_DL.Add(tmpobj); } objCollec = null; dgvDeliverNoteList.AutoGenerateColumns = false; objSourceDeliverNotes.DataSource = objCollec; dgvDeliverNoteList.DataSource = objSourceDeliverNotes; objSourceDeliverNotes.ResetBindings(true); txtDeliverNote.Text = ""; txtDeliverNote.Select(); } } return(true); // indicate that you handled this keystroke } if (keyData == Keys.F1) { frmTGRNList objForm = new frmTGRNList(CurrentUser, "Packing"); objForm.ShowDialog(this); } if (keyData == Keys.Escape) { DialogResult Result = MessageBox.Show(this, "Do you want to Exit", "Confirm", MessageBoxButtons.YesNo); if (Result == System.Windows.Forms.DialogResult.Yes) { this.Close(); } } // Call the base class return(base.ProcessCmdKey(ref msg, keyData)); }