Wrong row being removed from DGV


  • I am using the following event to remove then replace a row in a DGV.  I have used this method a number of times with no problems.  What is expected is that I double click on any cell of a row in the DGV and then that row is deleted and a new row is generated to replace it.  What is occurring is that the first row is always the one removed.  I have not had this problem before, so it is probably some simple thing in my code that is causing the problem.  If anyone can figure out what I have done wrong it would be appreciated.  I am sure that I will find it eventually, but eventually is often a long time later for me.

        Private Sub dgvTrainingList_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvTrainingList.CellDoubleClick
                    'Remove Trainee from training list
                    Me.TblDMTrainTableAdapter.FillByCRNum(Me._MasterBase2_0DataSet.tblDMTrain, glbintCRNum)
                    Dim strSignature As String = "Removed by Admin " + CStr(DateAndTime.Now)
                    Dim RemoveTrainingRow As _MasterBase2_0DataSet.tblDMTrainRow
                    RemoveTrainingRow = _MasterBase2_0DataSet.tblDMTrain.NewtblDMTrainRow()
                    RemoveTrainingRow.intTrainCRNum = glbintCRNum
                    RemoveTrainingRow.StrTrainName = glbstrName
                    RemoveTrainingRow.strTrainDept = glbstrDept
                    RemoveTrainingRow.strTrainUserName = glbstrLogin
                    RemoveTrainingRow.strTrainUserPassword = glbstrPassword
                    RemoveTrainingRow.strTrainSignature = strSignature
                    RemoveTrainingRow.blnTrainRemoved = CBool(True)
                    Me.TblDMTrainTableAdapter.FillByCRNum(Me._MasterBase2_0DataSet.tblDMTrain, glbintCRNum)
        End Sub


    Thursday, April 6, 2017 2:57 AM


  • A long time turned out to be a lot shorter than I though.  The problem turns out to be the first line of code.  It should not be there.  It is my guess that this causes two rows to be up for removal and the first is the one that is removed.  Anyway, removing the line below solved the problem.  for anyone who looks this over, thanks for your time.

    Me.TblDMTrainTableAdapter.FillByCRNum(Me._MasterBase2_0DataSet.tblDMTrain, glbintCRNum)


    • Marked as answer by gwboolean Thursday, April 6, 2017 3:03 AM
    Thursday, April 6, 2017 3:03 AM