Skip to content

Commit cfd8c48

Browse files
authored
How to get a tree node in mouse double click event in WPF TreeGrid (SfTreeGrid)?
How to get a tree node in mouse double click event in WPF TreeGrid (SfTreeGrid)?
1 parent 7334e56 commit cfd8c48

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
11
# How to get a tree node in mouse double click event in WPF TreeGrid (SfTreeGrid)?
22

3-
How to get a tree node in mouse double click event in WPF TreeGrid (SfTreeGrid)?
3+
## About the sample
4+
This example illustrates how to get a tree node in mouse double click event in WPF TreeGrid (SfTreeGrid)
5+
6+
In [SfTreeGrid](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.SfTreeGrid.html), you can get the [TreeNode](PointToCellRowColumnIndexhelp.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.TreeNode.html) based on row and column index from the mouse pointer position. The [TreeNode](PointToCellRowColumnIndexhelp.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.TreeNode.html) can be accessed by using any mouse events (example MouseDoubleClick event). This event is triggered when you double click on the [TreeNode](PointToCellRowColumnIndexhelp.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.TreeNode.html). Within this event, you can access the [TreeGridPanel](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.TreeGridPanel.html) by using the [GetTreePanel()](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.Helpers.TreeGridHelper.html#Syncfusion_UI_Xaml_TreeGrid_Helpers_TreeGridHelper_GetTreePanel_Syncfusion_UI_Xaml_TreeGrid_SfTreeGrid_) extension method that exists in the [Syncfusion.UI.Xaml.TreeGrid.Helpers](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.Helpers.html).
7+
8+
The row index of [TreeNode](PointToCellRowColumnIndexhelp.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.TreeNode.html) in the clicked position can be retrieved by resolving the mouse click position through [TreeGridPanel.PointToCellRowColumnIndex](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.TreeGridPanel.html#Syncfusion_UI_Xaml_TreeGrid_TreeGridPanel_PointToCellRowColumnIndex_System_Windows_Point_System_Boolean_). now, you can get the current [TreeNode](PointToCellRowColumnIndexhelp.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.TreeNode.html) by passing the **RowIndex** in [GetNodeAtRowIndex](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.TreeGridIndexResolver.html#Syncfusion_UI_Xaml_TreeGrid_TreeGridIndexResolver_GetNodeAtRowIndex_Syncfusion_UI_Xaml_TreeGrid_SfTreeGrid_System_Int32_) method in [SfTreeGrid](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.TreeGrid.SfTreeGrid.html).
9+
10+
11+
```C#
12+
13+
this.treeGrid.MouseDoubleClick += TreeGrid_MouseDoubleClick;
14+
15+
private void TreeGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
16+
{
17+
var treeGridPanel = this.treeGrid.GetTreePanel();
18+
// get the row and column index based on the pointer position
19+
var rowColumnIndex = treeGridPanel.PointToCellRowColumnIndex(e.GetPosition(treeGridPanel));
20+
if (rowColumnIndex.IsEmpty)
21+
return;
22+
var treeNodeAtRowIndex = treeGrid.GetNodeAtRowIndex(rowColumnIndex.RowIndex);
23+
MessageBox.Show("TreeNode : " + treeNodeAtRowIndex.ToString());
24+
}
25+
26+
```
27+
28+
![Shows the mouse double clicked TreeNode details in SfTreeGrid](GetTreeNodeViewMouseDoubleClick.gif)
29+
30+
## Requirements to run the demo
31+
Visual Studio 2015 and above versions
32+
33+

0 commit comments

Comments
 (0)