Debashish Mahonta

Debashish Mahonta

  • 1.6k
  • 164
  • 3.8k

Sum Datagrid Column with condition

Jun 28 2023 10:21 AM

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);
                }
            }

 


Answers (3)