DataGridView is meant to display data from the sources such as table or ModelsViews in a .Net application. Suppose you need to sum a columns which have many rows , say 1000 or more.

The general solution for this case is loop throw the row collection. We also use the Linq query for this task. The following example based on C#.Net FrameWork App.

                tq = dataGridView1.Rows.Cast<DataGridViewRow>().Sum(q => Convert.ToDouble(q.Cells[5].Value));  

We first cast the rows into DataGridViewRow and then invoke the sum function, that's it, cool ?


This free site is ad-supported. Learn more