12,629,107 members (35,399 online)
Rate this:
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
Posted 26-Jan-13 16:54pm

Rate this:

## Solution 1

You don't really. A DataGridView binds to a Data Source; read from that source.
Rate this:

## 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 :)
Linga Raja 29-Jan-13 7:50am

i l just try
for that also same idea or any other way is der
kshitij_CodeMaster 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
Marcus Kramer 30-Jan-13 9:50am

My 1. There is just way too much wrong with the way this code is written.
Rate this:

## Solution 2

how can i perform calculations on values in datagrid any idea?
or any other way of doing this
Rate this:

## 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();```
Rate this:

## 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

Top Experts
Last 24hrsThis month
 ppolymorphe 256 CHill60 150 OriginalGriff 150 Peter Leow 130 Richard MacCutchan 90
 OriginalGriff 1,379 ppolymorphe 1,032 John Simmons / outlaw programmer 615 Peter Leow 589 CPallini 531