Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 26-Jan-13 16:54pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You don't really. A DataGridView binds to a Data Source; read from that source.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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 Smile | :)
  Permalink  
Comments
Linga Raja at 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
kshitij_CodeMaster at 29-Jan-13 8:00am
   
jst assign price variable in above code the value tat u r fetching from db.
Linga Raja at 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
Marcus Kramer at 30-Jan-13 9:50am
   
My 1. There is just way too much wrong with the way this code is written.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

how can i perform calculations on values in datagrid any idea?
or any other way of doing this
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
 
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();
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.150224.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100