与DGV有一些问题。基本上,我正在检查txtH1, txtH2
等是否等于1, i
内的值。该值不会改变。如果它们相等,我希望将3, i
的值添加到txtP1, txtH2
等中包含的数值。
但是,我遇到的问题是DGV是用第一个值更新的,但之后没有。因此,在3,i
的第二次迭代中,txtP1.text的值未被添加到i
的值。
例如:
Column 1 | Column 4
John | 5
Nancy | 10
Bruce | 15
Frank | 20
如果John = 2 + 3,Nancy = 5 + 5,Bruce = 10 + 5和Frank = 15 + 5,它应该读什么。
但是,我得到的是:
Column 1 | Column 3
John | 2
Nancy | 5
Bruce | 10
Frank | 15
我希望这是有道理的。如果您需要进一步澄清,请告诉我 - 但请提前感谢您的帮助:这位初学者非常感谢!
For i As Integer = 0 To 3
If txtH1.Text = DataGridView5.Item(1, i).Value Then
DataGridView5.Item(3, i).Value = DataGridView5.Item(3, i).Value + txtP1.Text
ElseIf txtH2.Text = DataGridView5.Item(1, i).Value Then
DataGridView5.Item(3, i).Value = DataGridView5.Item(3, i).Value + txtP2.Text
ElseIf txtH3.Text = DataGridView5.Item(1, i).Value Then
DataGridView5.Item(3, i).Value = DataGridView5.Item(3, i).Value + txtP3.Text
ElseIf txtH4.Text = DataGridView5.Item(1, i).Value Then
DataGridView5.Item(3, i).Value = DataGridView5.Item(3, i).Value + txtP4.Text
ElseIf txtH5.Text = DataGridView5.Item(1, i).Value Then
DataGridView5.Item(3, i).Value = DataGridView5.Item(3, i).Value + txtP5.Text
ElseIf txtH6.Text = DataGridView5.Item(1, i).Value Then
DataGridView5.Item(3, i).Value = DataGridView5.Item(3, i).Value + txtP6.Text
ElseIf txtH7.Text = DataGridView5.Item(1, i).Value Then
DataGridView5.Item(3, i).Value = DataGridView5.Item(3, i).Value + txtP7.Text
ElseIf txtH8.Text = DataGridView5.Item(1, i).Value Then
DataGridView5.Item(3, i).Value = DataGridView5.Item(3, i).Value + txtP8.Text
End If
Next