Skip to content

SyncfusionExamples/how-to-get-a-tree-node-in-mouse-double-click-event-in-wpf-tree-grid

Repository files navigation

How to get a tree node in mouse double click event in WPF TreeGrid?

In WPF TreeGrid (SfTreeGrid), you can get the TreeNode based on row and column index from the mouse pointer position. The TreeNode can be accessed by using any mouse events (example MouseDoubleClick event). This event is triggered when you double click on the TreeNode. Within this event, you can access the TreeGridPanel by using the GetTreePanel extension method that exists in the Syncfusion.UI.Xaml.TreeGrid.Helpers.

The row index of TreeNode in the clicked position can be retrieved by resolving the mouse click position through TreeGridPanel.PointToCellRowColumnIndex. now, you can get the current TreeNode by passing the RowIndex in GetNodeAtRowIndex method in TreeGrid.

this.treeGrid.MouseDoubleClick += TreeGrid_MouseDoubleClick;

private void TreeGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
     var treeGridPanel = this.treeGrid.GetTreePanel();
     // get the row and column index based on the pointer position 
     var rowColumnIndex = treeGridPanel.PointToCellRowColumnIndex(e.GetPosition(treeGridPanel));
     if (rowColumnIndex.IsEmpty)
        return;
     var treeNodeAtRowIndex = treeGrid.GetNodeAtRowIndex(rowColumnIndex.RowIndex);                       
     MessageBox.Show("TreeNode : " + treeNodeAtRowIndex.ToString());
}

Shows the mouse double clicked TreeNode details in TreeGrid

Requirements to run the demo

Visual Studio 2015 and above versions

About

How to get row index of node in WPF TreeView (SfTreeView) ?

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5

Languages