Skip to content

Commit eb59108

Browse files
Merge pull request #1 from vijayarasan/main
How to get a tree node in mouse double click event in WPF TreeGrid (SfTreeGrid)?
2 parents af0f3de + 7b9223e commit eb59108

16 files changed

+725
-1
lines changed

App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
5+
</startup>
6+
</configuration>

App.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application x:Class="SfTreeGridDemo.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:SfTreeGridDemo"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
</Application.Resources>
8+
</Application>

App.xaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace SfTreeGridDemo
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
3.07 MB
Loading

MainWindow.xaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Window x:Class="SfTreeGridDemo.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:SfTreeGridDemo"
7+
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
8+
mc:Ignorable="d"
9+
Title="MainWindow" Height="450" Width="1000">
10+
<Window.DataContext>
11+
<local:ViewModel />
12+
</Window.DataContext>
13+
<Grid>
14+
<syncfusion:SfTreeGrid Name="treeGrid"
15+
AutoGenerateColumns="False"
16+
AllowEditing="True"
17+
ChildPropertyName="ReportsTo"
18+
ParentPropertyName="ID"
19+
ItemsSource="{Binding Employees}"
20+
SelfRelationRootValue="-1"
21+
AllowDraggingRows="True"
22+
AllowDrop="True">
23+
<syncfusion:SfTreeGrid.Columns>
24+
<syncfusion:TreeGridTextColumn MappingName="FirstName" HeaderText="First Name" />
25+
<syncfusion:TreeGridTextColumn MappingName="LastName" HeaderText="Last Name" />
26+
<syncfusion:TreeGridCheckBoxColumn MappingName="IsSelected" HeaderText="Is Selected" />
27+
<syncfusion:TreeGridTextColumn MappingName="ID" HeaderText="ID" />
28+
<syncfusion:TreeGridTextColumn MappingName="Title" HeaderText="Title" />
29+
<syncfusion:TreeGridCurrencyColumn MappingName="Salary" HeaderText="Salary" />
30+
<syncfusion:TreeGridTextColumn MappingName="ReportsTo" HeaderText="Reports To" />
31+
</syncfusion:SfTreeGrid.Columns>
32+
</syncfusion:SfTreeGrid>
33+
</Grid>
34+
</Window>

MainWindow.xaml.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Syncfusion.UI.Xaml.TreeGrid;
2+
using Syncfusion.UI.Xaml.TreeGrid.Helpers;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using System.Windows.Documents;
12+
using System.Windows.Input;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Imaging;
15+
using System.Windows.Navigation;
16+
using System.Windows.Shapes;
17+
18+
namespace SfTreeGridDemo
19+
{
20+
21+
/// <summary>
22+
/// Interaction logic for MainWindow.xaml
23+
/// </summary>
24+
public partial class MainWindow : Window
25+
{
26+
public MainWindow()
27+
{
28+
InitializeComponent();
29+
this.treeGrid.MouseDoubleClick += TreeGrid_MouseDoubleClick;
30+
}
31+
32+
private void TreeGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
33+
{
34+
var treeGridPanel = this.treeGrid.GetTreePanel();
35+
// get the row and column index based on the pointer position
36+
var rowColumnIndex = treeGridPanel.PointToCellRowColumnIndex(e.GetPosition(treeGridPanel));
37+
if (rowColumnIndex.IsEmpty)
38+
return;
39+
var treeNodeAtRowIndex = treeGrid.GetNodeAtRowIndex(rowColumnIndex.RowIndex);
40+
41+
MessageBox.Show("TreeNode : " + treeNodeAtRowIndex.ToString());
42+
}
43+
}
44+
}

Model.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.ComponentModel;
5+
using System.ComponentModel.DataAnnotations;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace SfTreeGridDemo
11+
{
12+
public class EmployeeInfo : IDataErrorInfo, INotifyDataErrorInfo
13+
{
14+
int _id;
15+
string _firstName;
16+
string _lastName;
17+
private string _title;
18+
decimal _salary;
19+
int _reportsTo;
20+
bool isSelected;
21+
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
22+
23+
public string FirstName
24+
{
25+
get { return _firstName; }
26+
set { _firstName = value; }
27+
}
28+
29+
public string LastName
30+
{
31+
get { return _lastName; }
32+
set { _lastName = value; }
33+
}
34+
35+
public bool IsSelected
36+
{
37+
get { return isSelected; }
38+
set { isSelected = value; }
39+
}
40+
41+
[Range(1, 2, ErrorMessage = "ID between 1 and 2 alone processed")]
42+
public int ID
43+
{
44+
get { return _id; }
45+
set { _id = value; }
46+
}
47+
48+
public string Title
49+
{
50+
get { return _title; }
51+
set { _title = value; }
52+
}
53+
54+
public decimal Salary
55+
{
56+
get { return _salary; }
57+
set { _salary = value; }
58+
}
59+
60+
public int ReportsTo
61+
{
62+
get { return _reportsTo; }
63+
set { _reportsTo = value; }
64+
}
65+
66+
[Display(AutoGenerateField = false)]
67+
68+
public string Error => string.Empty;
69+
70+
public string this[string columnName]
71+
{
72+
get
73+
{
74+
if (!columnName.Equals("Salary"))
75+
return string.Empty;
76+
if (this.Salary < 10000 || this.Salary > 30000)
77+
return "The 'Salary' field can range from 10000 to 30000 ";
78+
79+
return string.Empty;
80+
}
81+
}
82+
83+
[Display(AutoGenerateField = false)]
84+
85+
public bool HasErrors
86+
{
87+
get
88+
{
89+
return false;
90+
}
91+
}
92+
93+
private List<string> errors = new List<string>();
94+
public IEnumerable GetErrors(string propertyName)
95+
{
96+
if (!propertyName.Equals("Title"))
97+
return null;
98+
99+
if (this.Title.Contains("Management"))
100+
errors.Add("Management is not valid ");
101+
102+
return errors;
103+
}
104+
}
105+
}

Properties/AssemblyInfo.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[assembly: AssemblyTitle("SfTreeGrid_MVVM")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("")]
14+
[assembly: AssemblyProduct("SfTreeGrid_MVVM")]
15+
[assembly: AssemblyCopyright("Copyright © 2019")]
16+
[assembly: AssemblyTrademark("")]
17+
[assembly: AssemblyCulture("")]
18+
19+
// Setting ComVisible to false makes the types in this assembly not visible
20+
// to COM components. If you need to access a type in this assembly from
21+
// COM, set the ComVisible attribute to true on that type.
22+
[assembly: ComVisible(false)]
23+
24+
//In order to begin building localizable applications, set
25+
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
26+
//inside a <PropertyGroup>. For example, if you are using US english
27+
//in your source files, set the <UICulture> to en-US. Then uncomment
28+
//the NeutralResourceLanguage attribute below. Update the "en-US" in
29+
//the line below to match the UICulture setting in the project file.
30+
31+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32+
33+
34+
[assembly: ThemeInfo(
35+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36+
//(used if a resource is not found in the page,
37+
// or application resource dictionaries)
38+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39+
//(used if a resource is not found in the page,
40+
// app, or any theme specific resource dictionaries)
41+
)]
42+
43+
44+
// Version information for an assembly consists of the following four values:
45+
//
46+
// Major Version
47+
// Minor Version
48+
// Build Number
49+
// Revision
50+
//
51+
// You can specify all the values or you can default the Build and Revision Numbers
52+
// by using the '*' as shown below:
53+
// [assembly: AssemblyVersion("1.0.*")]
54+
[assembly: AssemblyVersion("1.0.0.0")]
55+
[assembly: AssemblyFileVersion("1.0.0.0")]

Properties/Resources.Designer.cs

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)