1
我的初始代码:复制两个不同的datagridview为一个datagridview的
Private Sub Transfer_Click(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView6.CellContentClick
Dim i As Integer
vTableTransfer = New DataTable
vTableTransfer.Columns.Add("Name", GetType(String))
vTableTransfer.Columns.Add("Type", GetType(String))
vTableTransfer.Columns.Add("Len", GetType(Double))
vTableTransfer.Columns.Add("ID", GetType(Double))
vTableTransfer.Columns.Add("OD", GetType(Double))
Try
For i = 0 To DataGridView6.Rows.Count - 3
If DataGridView6.Rows(i).Cells("Transfer").Value = True Then
vRow = vTableTransfer.NewRow
vRow.Item(0) = DataGridView13.Rows(i).Cells(0).Value
vRow.Item(1) = DataGridView6.Rows(i).Cells("Type").Value
vRow.Item(2) = DataGridView6.Rows(i).Cells("Len").Value
vRow.Item(3) = DataGridView13.Rows(i).Cells(2).Value
If IsDBNull(vRow.Item(3)) Then DataGridView13.Rows(i).Cells(2).Value = 0
If DataGridView13.Rows(i).Cells(2).Value = 0 Then DataGridView13.Rows(i).Cells(2).Value=DataGridView5.Columns.Item(1)
vRow.Item(4) = DataGridView6.Rows(i).Cells("OD").Value
If IsDBNull(vTableTransfer.Rows) Then Exit Sub
vTableTransfer.Rows.Add(vRow)
End If
Next
DataGridView12.DataSource = vTableTransfer
Catch ex As Exception
End Try
End sub
我有三个datagridview的(dgv6 & dgv13 & dgv5)其中dgv13是从dgv5复制然后将数据复制为一个datagridview的(dgv12)通过使用dgv6中的复选框列,dgv6上有12行数据,dgv13上有6行,程序在dgv13上的数据为空(计数步骤-7)后运行良好,然后程序被DBnull异常终止。我试图在dgv12上保留填充数据,而不是在dgv13中没有行数据,其中它们停止,然后复制dgv13中的前一个单元以完成将数据传输到dgv12。
我已经试用了cacth dbnull,并且放了一些代码来保持填充数据在dgv12上,但看起来像不工作,这可能是待办事项或任何其他方法,请告知...很多谢谢...