This question already has an answer here:
i have 2 dgvws in 2 forms.On dgvw 1 , there's a checkbox column. If a user checks a row's checkbox it is immediately copied to the 2nd dgvw in form 2 . The code is :
Private Sub userdatagrid_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles userdatagrid.CurrentCellDirtyStateChanged
If userdatagrid.IsCurrentCellDirty Then
userdatagrid.CommitEdit(DataGridViewDataErrorContexts.Commit)
Dim c, t As Integer
Selected.dg2.Columns.Clear()
For t = 0 To userdatagrid.Columns.Count - 1
Selected.dg2.Columns.Add(userdatagrid.Columns(t).Clone())
Next
For c = 0 To userdatagrid.Rows.Count - 1
If userdatagrid.Rows(c).Cells(0).Value = True Then
Selected.dg2.Rows.Add(userdatagrid.Rows(c).Cells(0).Value, userdatagrid.Rows(c).Cells(1).Value, userdatagrid.Rows(c).Cells(2).Value, userdatagrid.Rows(c).Cells(3).Value, userdatagrid.Rows(c).Cells(4).Value, userdatagrid.Rows(c).Cells(5).Value, userdatagrid.Rows(c).Cells(6).Value, userdatagrid.Rows(c).Cells(7).Value, userdatagrid.Rows(c).Cells(8).Value, userdatagrid.Rows(c).Cells(9).Value, userdatagrid.Rows(c).Cells(10).Value, userdatagrid.Rows(c).Cells(11).Value, userdatagrid.Rows(c).Cells(12).Value, userdatagrid.Rows(c).Cells(13).Value, userdatagrid.Rows(c).Cells(14).Value, userdatagrid.Rows(c).Cells(15).Value, userdatagrid.Rows(c).Cells(16).Value, userdatagrid.Rows(c).Cells(17).Value, userdatagrid.Rows(c).Cells(18).Value, userdatagrid.Rows(c).Cells(19).Value, userdatagrid.Rows(c).Cells(20).Value, userdatagrid.Rows(c).Cells(21).Value, userdatagrid.Rows(c).Cells(22).Value, userdatagrid.Rows(c).Cells(23).Value, userdatagrid.Rows(c).Cells(24).Value, userdatagrid.Rows(c).Cells(25).Value, userdatagrid.Rows(c).Cells(26).Value, userdatagrid.Rows(c).Cells(27).Value, userdatagrid.Rows(c).Cells(28).Value, userdatagrid.Rows(c).Cells(29).Value, userdatagrid.Rows(c).Cells(30).Value)
Else
For i As Integer = Selected.dg2.Rows.Count() - 1 To 0 Step -1
Dim row As DataGridViewRow
row = Selected.dg2.Rows(i)
Selected.dg2.Rows.Remove(row)
Next
End If
Next
Selected.dg2.Columns(0).Visible = False
Else
End If
My question is, suppose a user has checked a rows checkbox (which adds the row to the 2nd dgvw), then unchecks the it, i want to remove the just-added row from dgvw2 on checkbox uncheck...How to do so ?
Aucun commentaire:
Enregistrer un commentaire