How can i add mouse double click to data grid items wpf
wpf
Solution
You can handle the double-click on the DataGrid element, then look at the event source to find the row and column that was clicked:
private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
DependencyObject dep = (DependencyObject)e.OriginalSource;
// iteratively traverse the visual tree
while ((dep != null) && !(dep is DataGridCell) && !(dep is DataGridColumnHeader))
{
dep = VisualTreeHelper.GetParent(dep);
}
if (dep == null)
return;
if (dep is DataGridColumnHeader)
{
DataGridColumnHeader columnHeader = dep as DataGridColumnHeader;
// do something
}
if (dep is DataGridCell)
{
DataGridCell cell = dep as DataGridCell;
// do something
}
}
I describe this in detail in this blog post that I wrote.
Problem
In windows form application our data grid view has lots of event like row mouse double click or row click and extra ... But in WPF i cant find these event . How can i add row mouse double click to my user control that has a data grid in it i did it with some bad way that i used data grid mouse double click event and some bug happened in this way but i want know simple and standard way i also add double click event to data grid items in row_load event but it seems make my program slow if data grid has big source ``` private void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e) { e.Row.MouseDoubleClick += new MouseButtonEventHandler(Row_MouseDoubleClick); } ```