Skip to content

Commit dfb4709

Browse files
Merge pull request #1 from SaravananAyyanar/master
How to copy a column and paste it as a new column in wpf treegrid
2 parents 131ae30 + cc3b8f5 commit dfb4709

16 files changed

+850
-0
lines changed

SfTreeGridDemo/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>

SfTreeGridDemo/App.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
8+
</Application.Resources>
9+
</Application>

SfTreeGridDemo/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+
}

SfTreeGridDemo/Behavior.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Syncfusion.UI.Xaml.TreeGrid;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Controls;
8+
using System.Windows.Interactivity;
9+
using Syncfusion.UI.Xaml.TreeGrid;
10+
using System.Windows;
11+
using Syncfusion.Data;
12+
13+
namespace SfTreeGridDemo
14+
{
15+
class Behavior:Behavior<MainWindow>
16+
{
17+
protected override void OnAttached()
18+
{
19+
base.OnAttached();
20+
}
21+
}
22+
}

SfTreeGridDemo/Converter.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Data;
8+
9+
namespace SfTreeGridDemo
10+
{
11+
public class MultiCommandConverter : IMultiValueConverter
12+
{
13+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
14+
{
15+
return values.ToList();
16+
}
17+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
18+
{
19+
return null;
20+
}
21+
}
22+
}

SfTreeGridDemo/Helper.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Controls;
8+
using System.Windows.Input;
9+
10+
namespace SfTreeGridDemo
11+
{
12+
public class BaseCommand : ICommand
13+
{
14+
#region Fields
15+
16+
readonly Action<object> _execute;
17+
readonly Predicate<object> _canExecute;
18+
19+
20+
#endregion // Fields
21+
22+
#region Constructors
23+
24+
public BaseCommand(Action<object> execute)
25+
: this(execute, null)
26+
{
27+
}
28+
29+
public BaseCommand(Action<object> execute, Predicate<object> canExecute)
30+
{
31+
if (execute == null)
32+
throw new ArgumentNullException("execute");
33+
34+
_execute = execute;
35+
_canExecute = canExecute;
36+
}
37+
38+
39+
40+
#endregion // Constructors
41+
42+
#region ICommand Members
43+
44+
public bool CanExecute(object parameter)
45+
{
46+
return _canExecute == null ? true : _canExecute(parameter);
47+
}
48+
49+
public event EventHandler CanExecuteChanged
50+
{
51+
add { CommandManager.RequerySuggested += value; }
52+
remove { CommandManager.RequerySuggested -= value; }
53+
}
54+
55+
public void Execute(object parameter)
56+
{
57+
_execute(parameter);
58+
}
59+
60+
#endregion // ICommand Members
61+
}
62+
}

SfTreeGridDemo/MainWindow.xaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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:syncfusion="http://schemas.syncfusion.com/wpf"
5+
xmlns:interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:local="clr-namespace:SfTreeGridDemo"
9+
mc:Ignorable="d"
10+
Title="MainWindow"
11+
Height="350" Width="1000">
12+
13+
<Window.DataContext>
14+
<local:ViewModel/>
15+
</Window.DataContext>
16+
17+
<interactivity:Interaction.Behaviors>
18+
<local:Behavior/>
19+
</interactivity:Interaction.Behaviors>
20+
21+
<Window.Resources>
22+
<local:ViewModel x:Key="viewmodel"/>
23+
<local:MultiCommandConverter x:Key="converter"/>
24+
</Window.Resources>
25+
26+
<Grid>
27+
28+
<syncfusion:SfTreeGrid Name="treeGrid"
29+
Grid.Row="1"
30+
ChildPropertyName="ReportsTo"
31+
AutoExpandMode="AllNodesExpanded"
32+
ShowRowHeader="True"
33+
ItemsSource="{Binding Employees}"
34+
ParentPropertyName="ID"
35+
SelfRelationRootValue="-1">
36+
<syncfusion:SfTreeGrid.HeaderContextMenu>
37+
<ContextMenu ItemsSource="{Binding Menu,Source={StaticResource viewmodel}}" >
38+
<ContextMenu.ItemContainerStyle>
39+
<Style TargetType="MenuItem">
40+
<Setter Property="Command" Value="{Binding MyCommand,Source={StaticResource viewmodel}}"></Setter>
41+
<Setter Property="CommandParameter" >
42+
<Setter.Value>
43+
<MultiBinding Converter="{StaticResource ResourceKey=converter}">
44+
<Binding RelativeSource="{RelativeSource Self}"/>
45+
<Binding />
46+
</MultiBinding>
47+
</Setter.Value>
48+
</Setter>
49+
</Style>
50+
</ContextMenu.ItemContainerStyle>
51+
</ContextMenu>
52+
</syncfusion:SfTreeGrid.HeaderContextMenu>
53+
54+
</syncfusion:SfTreeGrid>
55+
56+
</Grid>
57+
</Window>

SfTreeGridDemo/MainWindow.xaml.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
namespace SfTreeGridDemo
17+
{
18+
/// <summary>
19+
/// Interaction logic for MainWindow.xaml
20+
/// </summary>
21+
public partial class MainWindow : Window
22+
{
23+
public MainWindow()
24+
{
25+
InitializeComponent();
26+
treeGrid.AllowDraggingColumns = true;
27+
}
28+
}
29+
}

SfTreeGridDemo/Model.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SfTreeGridDemo
8+
{
9+
public class EmployeeInfo
10+
{
11+
#region private variables
12+
int _id;
13+
private string _firstName;
14+
private string _lastName;
15+
private string _title;
16+
private double? _salary;
17+
private int _reportsTo;
18+
#endregion
19+
20+
#region public variables
21+
22+
/// <summary>
23+
/// Denotes the employee first name
24+
/// </summary>
25+
public string FirstName
26+
{
27+
get { return _firstName; }
28+
set { _firstName = value; }
29+
}
30+
31+
/// <summary>
32+
/// Denotes the employee last name
33+
/// </summary>
34+
public string LastName
35+
{
36+
get { return _lastName; }
37+
set { _lastName = value; }
38+
}
39+
40+
/// <summary>
41+
/// Denotes the employee id
42+
/// </summary>
43+
public int ID
44+
{
45+
get { return _id; }
46+
set { _id = value; }
47+
}
48+
49+
/// <summary>
50+
/// Denotes the employee title
51+
/// </summary>
52+
public string Title
53+
{
54+
get { return _title; }
55+
set { _title = value; }
56+
}
57+
58+
/// <summary>
59+
/// Denotes the employee salary
60+
/// </summary>
61+
public double? Salary
62+
{
63+
get { return _salary; }
64+
set { _salary = value; }
65+
}
66+
67+
/// <summary>
68+
/// Denotes the employee who has reports to
69+
/// </summary>
70+
public int ReportsTo
71+
{
72+
get { return _reportsTo; }
73+
set { _reportsTo = value; }
74+
}
75+
#endregion
76+
}
77+
}
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("SfTreeGridDemo")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("")]
14+
[assembly: AssemblyProduct("SfTreeGridDemo")]
15+
[assembly: AssemblyCopyright("Copyright © 2018")]
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")]

0 commit comments

Comments
 (0)