views:

112

answers:

2

Hi,

I want to execute some code when a a selected row of the WPF DataGrid is double clicked. I know that the datagrid has a MouseDoubleClicked event and that it also has a row selected event but I don't see any event for "selected row double clicked" ...

Do you think it's possible to capture this event somehow ?

Regards, Seb

A: 

Why don't you get the SelectedRow property while the DoubleClick event happens and do something with it? If the SelectedRow is null, it means no Row is selected so just return

private void Grid_DoubleClick(object sender, RoutedEventArgs e)
{
    if(grid.SelectedRow == null)
        return; // return if there's no row selected

    // do something with the Selected row here
}
Carlo
+1  A: 

you can add the event handler in the ItemContainerStyle (which is the style applied to a row) :

<DataGrid ... >
    <DataGrid.ItemContainerStyle>
        <Style TargetType="DataGridRow">
            <EventSetter RoutedEvent="MouseDoubleClick" Handler="Row_DoubleClick"/>
        </Style>
    </DataGrid.ItemContainerStyle>
    ...
</DataGrid>

Then, in the handler, you can check if the row is selected

Thomas Levesque