谢谢magicbacon(Cannot help coding)!
我要的就是:
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
感谢!散分
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
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
我是由VFP刚转VB.NET的,在VFP中处理很简单:
replace sum with price*quaty
但在VB.net中,我不知道如何写这个代码
看过论坛里的一些贴子,有兄弟说在后台用SQL语句搞掂,但问题是我的datagridview的数据源是一个临时的Datatable,和后台没关啊。
楼上的兄弟,能否指教一二,感激啊!