visual studio 2012 - total amount of the entire column in Datagridview passing to a textbox in c# -


how can overall total amount in datagridview textbox in same form?

// part calculating total amount of row  private void salesdatagrid_cellendedit(object sender, datagridviewcelleventargs e)     {         if (salesdatagrid != null)         {             (int x = 0; x < salesdatagrid.rows.count; x++)             {                 salesdatagrid.rows[x].cells[3].value = convert.toint32(salesdatagrid.rows[x].cells[1].value) *                     convert.todouble(salesdatagrid.rows[x].cells[2].value);               //and i've tried 1 below if work didn't              }             if (salesdatagrid != null)             {                 (int x = 0; x < salesdatagrid.rows.count; x++)                 {                     txtsalestotal.text = salesdatagrid.rows[x].cells[3].value.tostring() ;                 }              } 

try this:

double totalamount=0; (int x = 0; x < salesdatagrid.rows.count; x++) { totalamount += convert.todouble(salesdatagrid.rows[x].cells[3].value.tostring()); }  txtsalestotal.text=totalamount.tostring(); 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -