WPF DataGrid row double click event programmatically

You can do that in XAML by adding default style for DataGridRow under its resources section and declare event setter over there:

<DataGrid>
    <DataGrid.Resources>
        <Style TargetType="DataGridRow">
            <EventSetter Event="MouseDoubleClick" Handler="Row_DoubleClick"/>
        </Style>
    </DataGrid.Resources>
</DataGrid>

OR

In case want to do it in code behind. Set x:Name on grid, create style programatically and set the style as RowStyle.

<DataGrid x:Name="dataGrid"/>

and in code behind:

Style rowStyle = new Style(typeof(DataGridRow));
rowStyle.Setters.Add(new EventSetter(DataGridRow.MouseDoubleClickEvent,
                         new MouseButtonEventHandler(Row_DoubleClick)));
dataGrid.RowStyle = rowStyle;

AND

There is example of event handler:

  private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
  {
     DataGridRow row = sender as DataGridRow;
     // Some operations with this row
  }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)