I want to sum a datagrid column with where condition which data is loaded from an excel file. I use the following code to sum but its not show result at a time. It shows again again up to finish. But i want to sum datagrid column at a time and i want to sum with multiple condition. How can i do it?
decimal sum = 0; for (int i = 0; i < DataGridImp.Rows.Count - 1; i++) { if (DataGridImp.Rows[i].Cells["L.AC_No"].Value.ToString() == "90100000010" && DataGridImp.Rows[i].Cells["L.AC_No"].Value != null) { sum += Convert.ToDecimal(DataGridImp.Rows[i].Cells["L.Balance"].Value) / 100000; MessageBox.Show(Convert.ToString(sum.ToString("#.##")), "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } }