13,549,093 members
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 15:54pm

## Solution 1

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

## 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
kshitij2410131 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
algioethqnbalkerunb 30-Jan-13 9:50am

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

## Solution 2

how can i perform calculations on values in datagrid any idea?
or any other way of doing 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();```

## 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
 OriginalGriff 215 Richard MacCutchan 105 ppolymorphe 100 Afzaal Ahmad Zeeshan 50 PIEBALDconsult 35
 OriginalGriff 4,870 ppolymorphe 2,057 Richard MacCutchan 1,971 Wendelius 1,865 Maciej Los 1,515