这是我的代码:VB的DataGridView计算?
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.Columns.Clear()
Dim newTable As New DataTable
newTable.Columns.Add("Column1")
newTable.Columns.Add("Column2")
newTable.Columns.Add("Column3")
newTable.Rows.Add("1", "4", "")
newTable.Rows.Add("10", "2", "")
newTable.Rows.Add("20", "5", "")
DataGridView1.DataSource = newTable
Try
Dim iCell1 As Integer
Dim icell2 As Integer
Dim icellResult As Integer
iCell1 = DataGridView1.CurrentRow.Cells(0).Value
icell2 = DataGridView1.CurrentRow.Cells(1).Value
icellResult = iCell1 * icell2
DataGridView1.CurrentRow.Cells(2).Value = icellResult
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
的栏3 =列1列2 *。 在我上面的代码中,只有第一行是正确的。我想第3栏显示值4,20,和100
我必须在哪写代码? – valzz 2014-09-21 11:19:16
在Load子代的末尾,代替DataGridView1.CurrentRow.Cells(2).Value = icellResult – TheCreepySheep 2014-09-21 13:44:59
如果您发现我的答案有帮助,请将其标记为已接受 – TheCreepySheep 2014-09-21 14:50:14