這是我的代碼: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