Hi
I am beginner in c#, I have the following column in a gridview
item, qty, rate, total. The total of each row should be added to a another textbox in a form to get net total. The following is my code
private void dataGridViewInvoice_CellEndEdit(object sender, DataGridViewCellEventArgs e){
for (int i = 0; i < dataGridViewInvoice.Rows.Count; i++)
{
DataGridViewCell MyCell = dataGridViewInvoice[e.ColumnIndex, e.RowIndex];
if (MyCell.Value != null)
{
decimal quantity;
decimal rate, price;
quantity = 0;
rate = 0;
decimal totalprice;
totalprice = 0;
if (dataGridViewInvoice.Rows[e.RowIndex].Cells["InvQty"].Value != null)
{
quantity = decimal.Parse(dataGridViewInvoice.Rows[e.RowIndex].Cells["InvQty"].Value.ToString());
}
if (dataGridViewInvoice.Rows[e.RowIndex].Cells["InvRate"].Value != null)
{
rate = decimal.Parse(dataGridViewInvoice.Rows[e.RowIndex].Cells["InvRate"].Value.ToString());
}
price = quantity * rate;
dataGridViewInvoice.Rows[e.RowIndex].Cells["InvTotal"].Value = price.ToString();
// txtTotal.Text = should be shown here
}
Many Thanks
Pol
polachan