I have a form with two tabs, each with a DataGridView. DGV1 on Tab1 is bound to a DataTable on form load. DGV2 on Tab2 is not bound on form load, but includes a CheckBoxColumn to be utilized later.
When I select a row in DGV1, DGV2 is populated and I set each checkbox on DGV2 to True.
However, after a cell in DGV1 is clicked and DGV2 is subsequently populated and the checkboxes are set to True, they are reverted to Nothing when I first go to Tab2. However, once I have "seen" DGV2 by clicking the second tab, I can go back to DGV1 and click the same row, and now the checkboxes will actually be checked.
I have tried using Refresh and RefreshEdit to no avail.
Public Class Form1
Private ConnectionString As String = "..."
Private Function GetDataTable(selectString) As DataTable
Dim adapter As New SqlDataAdapter(selectString, ConnectionString)
Dim dt As New DataTable
Dim bs As New BindingSource
adapter.Fill(dt)
bs.DataSource = dt
Return dt
End Function
Private Sub Form1_Load(...) Handles Me.Load
DGV1.DataSource = GetDataTable("SELECT * FROM ...")
End Sub
Private Sub DGV1_CellClick(...) Handles DGV1.CellClick
DGV2.DataSource = GetDataTable("SELECT * FROM ...")
For i = 0 To dt.Rows.Count - 1
DGV2.Item(0, i).value = True
Next
End Sub
End Class
This seems to only apply to the CheckBoxColumn, as I can programatically edit other non-checkbox cells in the same manner and the changes are committed correctly. Any suggestions?
Aucun commentaire:
Enregistrer un commentaire