Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
(the column is of Price so i need to get every cell value of that column and total it) note that columns are auto generated
Posted
Comments
Suvendu Shekhar Giri 4-Nov-15 12:23pm    
What kind application is it? ASP.Net or WPF?
Member 10528646 5-Nov-15 13:06pm    
WPF
Suvendu Shekhar Giri 5-Nov-15 13:09pm    
Remove the ASP.Net tag from the question.
Suvendu Shekhar Giri 5-Nov-15 13:22pm    
How are you binding the datagrid? from a datatable?

Loop through all the rows of Datagrid.

Inside the loop, find the column value for the row and sum that using a variable.
 
Share this answer
 
Instead of doing the sum in the datagridview, you can do that in the datasource you are using to bind the datagrid.

For example, if you are using datatable as the source for binding datagrid then you can find the sum doing something like-
C#
double total = 0;
foreach (var myRow in myTable)
{
    total += double.Parse(myRow["MyValue"].ToString());
}


To get back the datatable at some other place than the binding datagrid, you write something like-
C#
Datatable dt = (Datatable) myDatagrid.ItemsSource;


Hope, it helps :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900