怎么在Datagridview中进行列间的计算

如何在Datagridview中进行列间的计算?
举例:
        Datagridview有三列,分别是price、quaty、sum
        我想设置成sum=price*quaty
在论坛搜了一下贴,发现类似的问题不少,但我还是没有解决,请知道的兄弟指教,多谢


------解决方案--------------------
指教不敢当,呵呵。其实很简单,就是把前两项的数据相乘,放到第三项中。您只要会操作单元格中的数据自然就会了。写的潦草,还望见谅。

Public Class Form1

Dim conn As Data.OleDb.OleDbConnection
Dim da As Data.OleDb.OleDbDataAdapter
Dim ds As Data.DataSet

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DataGridView1.AllowUserToOrderColumns = False
conn = New OleDb.OleDbConnection( "Provider=Microsoft.Jet.OleDb.4.0;Data Source=D:\data.mdb ") ' 假设表中有两项: "price "和 "quaty "
conn.Open()
da = New OleDb.OleDbDataAdapter( "SELECT * FROM 表1 ", conn)
ds = New Data.DataSet
da.Fill(ds)
conn.Close()
DataGridView1.DataSource = ds.Tables(0)
DataGridView1.Columns.Add( "sum ", "sum ") ' 加入一项 "sum "
For i As Int32 = 0 To DataGridView1.Rows.Count - 1
DataGridView1.Rows(i).Cells(2).Value = DataGridView1.Rows(i).Cells(0).Value * DataGridView1.Rows(i).Cells(1).Value '把前两项的数据相乘,放到第三项中
Next
End Sub

End Class
------解决方案--------------------
在DataGridView的CellEndEdit事件中加入以下代码即可:

Private Sub dgrd4_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgrd4.CellEndEdit
Try

If Me.dgrd4.Rows(e.RowIndex).IsNewRow = False Then
If IsNumeric(Me.dgrd4.Rows(e.RowIndex).Cells( "Price ").Value) = False Then
Me.dgrd4.Rows(e.RowIndex).Cells( "Price ").Value = Math.Round(0, 2)
End If

If IsNumeric(Me.dgrd4.Rows(e.RowIndex).Cells( "quaty ").Value) = False Then
Me.dgrd4.Rows(e.RowIndex).Cells( "quaty ").Value = Math.Round(0, 2)
End If


Me.dgrd4.Rows(e.RowIndex).Cells( "sum ").Value = Math.Round(Me.dgrd4.Rows(e.RowIndex).Cells( "Price ").Value * Me.dgrd4.Rows(e.RowIndex).Cells( "quaty ").Value, 2)
End If
End If

End If

Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
End Try