private void ControlKeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { if (sender == SearchProduct && SearchProduct.EditValue != null) { spLength.Focus(); } else if (sender == spPrice) { spLength.Focus(); } else if (sender == spLength) { spWidth.Focus(); } else if (sender == spWidth) { spQuantity.Focus(); } else if (sender == spQuantity) { spDiscount.Value = (spPrice.Value * spLength.Value * spWidth.Value * spQuantity.Value) - (int)(spPrice.Value * spLength.Value * spWidth.Value * spQuantity.Value); spDiscount.Focus(); } else if (sender == spDiscount) { ProductView.AddNewRow(); SearchProduct.EditValue = null; SearchProduct.Focus(); } } else if (e.KeyCode == Keys.Delete) { if (sender == ProductView) { if (ProductView.RowCount > 0) { SpInvoiceDiscount.Value = SpInvoiceDiscount.Value - decimal.Parse(ProductView.GetRowCellValue(ProductView.FocusedRowHandle, ProductView.Columns[9]).ToString()); spInvoiceTotal.Value = spInvoiceTotal.Value - decimal.Parse(ProductView.GetRowCellValue(ProductView.FocusedRowHandle, ProductView.Columns[10]).ToString()); ProductView.DeleteRow(ProductView.FocusedRowHandle); SearchProduct.Focus(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }