private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0 && dataGridView1[e.ColumnIndex, e.RowIndex].Value != null) { product p = new product(); string q = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); if (p.search(q)) { dataGridView1[1, e.RowIndex].Value = p.name; // dataGridView1[7, e.RowIndex].Value = p.stk; dataGridView1[5, e.RowIndex].Value = p.sr; SendKeys.Send("{UP}"); SendKeys.Send("{Right}"); SendKeys.Send("{Right}"); } else { MessageBox.Show("Invalid Product Code"); SendKeys.Send("{UP}"); return; } } else if (e.ColumnIndex == 2 && dataGridView1[e.ColumnIndex, e.RowIndex].Value != null) { dataGridView1[3, e.RowIndex].Value = null; dataGridView1[4, e.RowIndex].Value = null; SendKeys.Send("{UP}"); SendKeys.Send("{Right}"); } else if (e.ColumnIndex == 3 && dataGridView1[e.ColumnIndex, e.RowIndex].Value != null) { dataGridView1[2, e.RowIndex].Value = null; dataGridView1[4, e.RowIndex].Value = null; SendKeys.Send("{UP}"); SendKeys.Send("{Right}"); } else if (e.ColumnIndex == 4 && dataGridView1[e.ColumnIndex, e.RowIndex].Value != null) { dataGridView1[3, e.RowIndex].Value = null; dataGridView1[2, e.RowIndex].Value = null; SendKeys.Send("{UP}"); SendKeys.Send("{Right}"); } else if (e.ColumnIndex < dataGridView1.Columns.Count - 3) { SendKeys.Send("{UP}"); SendKeys.Send("{Right}"); } else if (e.ColumnIndex == 5) { int col = e.ColumnIndex; dataGridView1.CurrentCell = dataGridView1[0, e.RowIndex]; int row = e.RowIndex, unit, rate, amount; if (dataGridView1[2, e.RowIndex].Value != null) { unit = Convert.ToInt32(dataGridView1[2, e.RowIndex].Value); } else if (dataGridView1[3, e.RowIndex].Value != null) { unit = Convert.ToInt32(dataGridView1[3, e.RowIndex].Value); } else { unit = Convert.ToInt32(dataGridView1[4, e.RowIndex].Value); } rate = Convert.ToInt32(dataGridView1[col, row].Value); amount = unit * rate; dataGridView1[col + 1, row].Value = amount; } counter(); }