这是我的初始代码,
Private Sub Create_vTable()
Dim i,j As Integer
Dim q, PV, YP, MW, id As Double
q = TextBox1.Text
MW = TextBox2.Text
PV = TextBox3.Text
YP = TextBox4.Text
vTable = New DataTable
vTable.Columns.Add("Name", GetType(String))
vTable.Columns.Add("Len", GetType(Double))
vTable.Columns.Add("ID", GetType(Double))
vTable.Columns.Add("OD", GetType(Double))
vTable.Columns.Add("Totlen", GetType(Double))
vTable.Columns.Add("Vel", GetType(Double))
id = DGV6.CurrentRow.Cells(2).Value
For i = 0 To DGV6.Rows.Count - 2
vRow = vTable.NewRow
vRow.Item(5) = (q / (2.448 * (id) ^ 2))
For j = 0 To DGV6.Columns.Count - 1
vRow.Item(j) = DGV.Rows(i).Cells(j).Value.ToString
Next
vTable.Rows.Add(vRow)
Next
Catch ex As Exception
End Try
End Sub
我有DGV6和文本框中的数据,我喜欢在每个单元格的数据表项目5上进行计算但是在测试之后,结果显示只有一个计算了不跟随每个单元格的整个列,任何人都可以提供帮助,在此先感谢
答案 0 :(得分:0)
您只能从DataGridView中的一行获取id
值。您必须在每次循环迭代中获得它的值:
For i = 0 To DGV6.Rows.Count - 2
vRow = vTable.NewRow
id = DGV.Rows(i).Cells(2).Value
vRow.Item(5) = (q / (2.448 * (id) ^ 2))
For j = 0 To DGV6.Columns.Count - 1
vRow.Item(j) = DGV.Rows(i).Cells(j).Value.ToString
Next
vTable.Rows.Add(vRow)
Next