John
John

Reputation: 1338

How do i disable doubleclicking on the header of a datagridview

I have a datagridview in my application that has some rows in it. I want to user to be able to double click on the row and have it do something. But if they double click on the header, it also does the same action using the highlighted row. Double clicking the header does the same thing as double clicking on a row. I don't want to disable the header and disable column sorting, I just want to disable double clicking on the header.

Upvotes: 1

Views: 2188

Answers (2)

David Wilson
David Wilson

Reputation: 4439

Create a boolean variable in your form's class called EnableRowHeaderDoubleClick and set it to false then add this code

Private Sub DataGridView1_RowHeaderMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.RowHeaderMouseDoubleClick
    If EnableRowHeaderDoubleClick = False Then Exit Sub
End Sub

Upvotes: 1

41686d6564
41686d6564

Reputation: 19641

In either CellDoubleClick or CellContentDoubleClick event you can use the following code:

If e.RowIndex <> -1 Then
    'Trigger some actions
End If

You might also use e.ColumnIndex <> -1 to avoid double clicking on the row header.

Upvotes: 0

Related Questions