Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF datagrid selected row clicked event ?

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 ?

like image 280
MadSeb Avatar asked Jun 25 '10 18:06

MadSeb


1 Answers

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

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

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

private void Row_DoubleClick(object sender, MouseButtonEventArgs e) {     // execute some code } 
like image 145
Thomas Levesque Avatar answered Sep 22 '22 00:09

Thomas Levesque