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);
}
}
Amit MohantyPosted Jun 28, 2023, 11:02 AM
Or you can try this:
Debashish MahontaPosted Jun 28, 2023, 10:57 AM
How can i add multiple condition? Like
DataGridImp.Rows[i].Cells["L.AC_No"].Value.ToString() == "90100000010","90100000012","90100000015","90100000009")
Amit MohantyPosted Jun 28, 2023, 10:27 AM