Click here to Skip to main content
15,885,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to retrieve the column values of the data grid and have to make calculation on it
how can i do it?
plz help
and thanx in advance..
Posted

You don't really. A DataGridView binds to a Data Source; read from that source.
 
Share this answer
 
may be below code cn help u.

for (int i=0;i<datagridview1.rows.count;i++)>
{
double price =5.0;
double totalamt= Convert.ToDouble(DataGridView1.Rows[i].Cells["qty"].Value.ToString()) * (price);
DataGridView1.Rows[i].Cells["qty"].Value = totalamt;
}


i hope this code will help u achieve ur task
Enjoy :)
 
Share this answer
 
Comments
Linga Raja 29-Jan-13 7:50am    
i l just try
but my price will be retrieved from database
for that also same idea or any other way is der
[no name] 29-Jan-13 8:00am    
jst assign price variable in above code the value tat u r fetching from db.
Linga Raja 30-Jan-13 4:33am    
i hav 7 different tables for all weekdays
if day is monday then monday table purchase price should be assigned
and how can i use it inside the for loop
purchase price depends on a particular item(newspaper)
can u suggest an idea
fjdiewornncalwe 30-Jan-13 9:50am    
My 1. There is just way too much wrong with the way this code is written.
how can i perform calculations on values in datagrid any idea?
or any other way of doing this
 
Share this answer
 
Hi Linga Raja you can use below code for your problem,I think it will be solve your problems. if you have any query fill free to reply
Thanks
Vivek
XML
int myDatarow = 0;
            double amt = 0;
          myDatarow=  dGNew.Rows.Count;// here dG isData Grid
          for (int i = 0; i &amp;lt; myDatarow; i++)
          {
              amt = amt + Convert.ToDouble(dGNew.Rows[i].Cells[3].Value.ToString());// here cells[3] is cell no you can use cell name/ID like  dGNew.Rows[i].Cells[&amp;quot;amount&amp;quot;].Value.ToString()
          }
          lbltotalAmount.text = amt.ToString();
 
Share this answer
 
vivek but i want to show the calculated value back in the datagridview

papername qty amount these are three columns in datagridview

user will enter qty and amount has to be calculated by retrieving value frm database
and shown in amount column
and thanx vivek for ur idea
 
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