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

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -