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上,但看起來像不工作,這可能是待辦事項或任何其他方法,請告知...很多謝謝...