Results 1 to 2 of 2

Thread: [RESOLVED] Double Click Event only selects first row of a set of rows in DGV

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Resolved [RESOLVED] Double Click Event only selects first row of a set of rows in DGV

    I am making a Double-Click selection of a row in a DGV.

    The sequence is that a form, call it SignList is displayed, showing all rows from a table that meet a criteria. By clicking the Add button on this form a second form, PickList, is opened with a DGV that displays of all of the employees, by department. I then make a selection from the combobox and the same form redisplays all of the employees that are in the same department.

    At this point the DGV is enabled and I would double click anywhere in the row of the one person to be added to SignList. The problem is that whatever row I choose, only the first row is actually selected, as established by checking the value of glbintEmployeeID after being assigned(see the line with red text).

    So what is it that I am so obviously missing here?


    SignList
    Name:  SignList.jpg
Views: 314
Size:  21.7 KB

    PickList before combobox selection
    Name:  PickList1.jpg
Views: 307
Size:  160.2 KB

    PicList after combobox selection
    Name:  PickList.jpg
Views: 298
Size:  97.0 KB

    Code:
        Private Sub dgvPickList_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvPickList.CellDoubleClick
            'Define values for selected employee
            glbintEmployeeID = CInt(CType(tblEmployeeBindingSource.Current, DataRowView).Item("intEmployeeID"))
            Select Case glbintCount
                Case 1
                    'Add individual to approver list
                    Dim LoadApprover As New nspSubPicklist.DataLoadProperties
                    LoadApprover.AddApprover()
                    Me.Close()
                    'Dim EnableWindow As New nspMasterBaseOperations.ControlRoutines
                    'glbfrmWindowForm = frmSignList
                    'EnableWindow.EnableWindow()
                Case 2
                    'Add individual to Trainee list
                    Dim LoadTrainee As New nspSubPicklist.DataLoadProperties
                    LoadTrainee.AddTrainee()
                    Me.Close()
                Case Else
                    'Dim ErrorMessage As New nspMasterBaseOperations.ErrorMessage
                    'MessageBox.Show(String.Format("{0}", ErrorMessage.Error1002(glbstrErrorMessage)))
                    Try
                        Throw _Exception
                    Catch ex As Exception
                        Dim ErrorMessage As New nspMasterBaseOperations.ErrorMessage
                        MessageBox.Show(String.Format("{0}{1} StackTrace:{2}", ErrorMessage.Error1002(glbstrErrorMessage), vbNewLine, ex.StackTrace))
                        frmProcessList.Close()
                        mnuMain.Show()
                    End Try
            End Select
        End Sub

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    703

    Re: Double Click Event only selects first row of a set of rows in DGV

    I figured it out. Funny how that frequently seems to occur after I have asked the question. Anyway, the error is the line:

    glbintEmployeeID = CInt(CType(tblEmployeeBindingSource.Current, DataRowView).Item("intEmployeeID"))

    is wrong, and I think (maybe) I can see why. The line should have been:

    glbintEmployeeID = CInt(Me.dgvPickList.Rows(e.RowIndex).Cells(0).Value.ToString)

    I have made this mistake before. I do have a hard time understanding why they do not produce the same result, but I am guessing that the reason is the, "Current" in the line I first used will only point to the first row?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width