how I can show the sum of in a datagridview column?

Viewed 125265

I need to show the sum of the count column from this datagridview, but I don't know how I can get to the data in the datagridview.

When I click on the button, I want to show 94 in label1.

How can this be done?

alt text

9 Answers

So, you can accomplish this by Using LINQ like so the next code

label1.Text = (from DataGridViewRow row in datagridview1.Rows
                                 where !String.IsNullOrEmpty(row.Cells[1].FormattedValue.ToString())
                                 select Convert.ToDouble(row.Cells[1].FormattedValue)).Sum().ToString();
Related