How to disable double-click the header of a Datagrid?

Asked

Viewed 441 times

0

Double-click method on the grid:

    private void grid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
      if (e.LeftButton == MouseButtonState.Pressed && //Verifica clique com o esquerdo
          uldPo00100.SelectedItems.Count > 0) //Verifica item selecionado 
          //Comandos para abrir nova janela

Usually, in single click, a grid item is selected, and in double click, execute the above method.

Problem: When an item is selected, and double-click on the header, or on the white part of the grid, the same method is executed..

Is there a check if the double click is on the same line, or different from the header? Or is there any event to click the header? Remembering that it is Datagrid, not Datagridview..

  • You can try taking the cell under the cursor according to this answer: http://stackoverflow.com/a/25503438/1291717 and then decide what to do with the double-click Handle

2 answers

0

Remove Handler from the event

 EventHandler eventHandler = new EventHandler(dataGridView_CellContentDoubleClick);
 dataGridView.CellContentDoubleClick -= eventHandler; 

0

I believe it is not possible to disable. Alternatively you can skip douplo by clicking the header:

private void grid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    DataGridView.HitTestInfo hit = grid.HitTest(e.X, e.Y);
    if (hit.Type == DataGridViewHitTestType.ColumnHeader)
    {
        return;
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.