vb.net怎么计算datagridview指定单元格的数据求和
--------------------编程问答-------------------- 有人知道吗? 还是我说的不清楚? 说句话啊 --------------------编程问答-------------------- 首先,代码要写在“”之内哦,不是写在这个后面 --------------------编程问答-------------------- drows(0).Item(6) = drows(1).Item(6) + drows(2).Item(6)这个表示,第0行第六列等于,第一行第六列与第二行第六列的加和 --------------------编程问答-------------------- 哦 原来如此 新手 勿怪啊。。 --------------------编程问答-------------------- 帮顶下 --------------------编程问答--------------------
DataGridView1.DataSource = Nothing
MyDs.Clear()
Dim SQLStr As String = "Select num as 编号,jine as 金额,date as 日期,name as 经手人,type as 项目,inorout as 收支,bz as 备注 From rcsz where date between '" & DateTimePicker1.Value & "' and '" & DateTimePicker2.Value & "'"
Mycom.Connection = Mycon
Mycom.CommandType = CommandType.Text
Mycom.CommandText = SQLStr
MyDataAdapter.SelectCommand = Mycom
MyDataAdapter.Fill(MyDs, "rcsz")
Dim idx As Integer
Dim totalIN As Integer = 0 '总收入
Dim totalOUT As Integer = 0 '总支出
'根据inorout的内容计算总收入与总支出
For idx = 0 To MyDs.Tables("rcsz").Rows.Count - 1
If MyDs.Tables("rcsz").Rows(idx)(5).ToString().Trim() = "收入" Then
totalIN = totalIN + CInt(MyDs.Tables("rcsz").Rows(idx)(1).ToString().Trim())
ElseIf MyDs.Tables("rcsz").Rows(idx)(5).ToString().Trim() = "支出" Then
totalOUT = totalOUT + CInt(MyDs.Tables("rcsz").Rows(idx)(1).ToString().Trim())
End If
Next
'添加总收入行
Dim drIN As DataRow = MyDs.Tables("rcsz").NewRow()
drIN.Item(0) = "总收入:"
drIN.Item(1) = totalIN.ToString().Trim()
MyDs.Tables("rcsz").Rows.Add(drIN)
'添加总支出行
Dim drOUT As DataRow = MyDs.Tables("rcsz").NewRow()
drOUT.Item(0) = "总支出:"
drOUT.Item(1) = totalOUT.ToString().Trim()
MyDs.Tables("rcsz").Rows.Add(drOUT)
navigator = Me.BindingContext(MyDs, "rcsz")
DataGridView1.DataSource = MyDs
DataGridView1.DataMember = "rcsz"
补充:.NET技术 , VB.NET