Handling a double mouseclick on DGV ColumnHeaders?

I have a DataGridView in which the User is presented with a TabControl containing two TabPages. The first TabPage contains a DataGridView control which lists "Detail" records. The second TabPage contains various controls in which to edit the row of data selected from the DGV.

In order for a User to edit a row of data, they need to double-click on a specific row...when they do that, the row of data is selected and the program will populate the controls on the second TabPage and the second TabPage will then have focus.

The problem that I am having is that if the User happens to double-click on a Column Header and not a specific row of data, the DataGridView_DoubleClick event fires and makes the second TabPage have the focus...which is what the DoubleClick event is suppose to do but not when a Column Header is double-clicked on.

I thought that if a Column Header was double-clicked, the DataGridView1_ColumnHeaderMouseDoubleClick() Event would fire but it doesn't appear to be as I have set a breakpoint in that event. What's the best way to handle a Double-Click on the Column Header? I have my code below.

        Private Sub dgvEquipment_ColumnHeaderMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvEquipment.ColumnHeaderMouseDoubleClick
        blnColHeaderWasClicked = True
    End Sub

        Private Sub dgvEquipment_DoubleClick(sender As Object, e As EventArgs) Handles dgvEquipment.DoubleClick
            Dim row As DataGridViewRow = dgvEquipment.CurrentRow

            If blnColHeaderWasClicked Then
                blnColHeaderWasClicked = False
            End If

        Catch ex As Exception
            strErr = gfrmID & "/dgvEquipment_DoubleClick() - " & ex.Message
            MessageBox.Show(strErr, "User Notification", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
Who is Participating?
ChloesDadConnect With a Mentor Commented:
In your event  

Private Sub dgvEquipment_DoubleClick(sender As Object, e As EventArgs) Handles dgvEquipment.DoubleClick

you can check for the row number being 0 and if it is then ignore it as that's the column header row.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.