private void TXT_DISCOUNT_KeyDown(object sender, KeyEventArgs e) { if(e.KeyCode==Keys.Enter) { if (ORDER.VERIFIY_QUANTITY(TXT_ID_PRODUCT.Text, Convert.ToInt32(TXT_QUA.Text)).Rows.Count < 1) { MessageBox.Show(" الكميه المدخله لهذا المنتج غير متوفره", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } for (int i=0;i<dataGridView1.Rows.Count-1;i++) { if (dataGridView1.Rows[i].Cells[0].Value.ToString() == TXT_ID_PRODUCT.Text) { MessageBox.Show("هذا المنتج تم ادخاله مسبقا ", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } DataRow r = DT.NewRow(); r[0] = TXT_ID_PRODUCT.Text; r[1] = TXT_NAME_PRODUCT.Text; r[2] = TXT_PRICE.Text; r[3] = TXT_QUA.Text; r[4] = TXT_AMOUNT.Text; r[5] = TXT_DISCOUNT.Text; r[6] = TXT_TO_AMOUNT.Text; DT.Rows.Add(r); dataGridView1.DataSource = DT; CLEAR_TXTS(); button1.Focus(); TXT_TOTAL_AMOUNT.Text = (from DataGridViewRow row in dataGridView1.Rows where row.Cells[6].FormattedValue.ToString() != string.Empty select Convert.ToDouble(row.Cells[6].FormattedValue)).Sum().ToString(); //double[] array = new double[dataGridView1.RowCount]; //double summ = 0; //for (int i = 0; i < dataGridView1.Rows.Count-1; i++) //{ // //array[i] = Convert.ToDouble(dataGridView1.CurrentRow.Cells[6].Value.ToString()); // summ += Convert.ToDouble(dataGridView1.CurrentRow.Cells[6].Value.ToString()); //} ////TXT_TOTAL_AMOUNT.Text = array.Sum().ToString(); //TXT_TOTAL_AMOUNT.Text = summ.ToString(); } }