Skip to content

Commit caffc9f

Browse files
author
saravanan.ayyanar
committed
This example explains how to merge cells in a row in wpf treegrid
1 parent 3473e09 commit caffc9f

19 files changed

+1193
-0
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.0"/>
5+
</startup>
6+
</configuration>

App.ico

4.19 KB
Binary file not shown.

App.xaml

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

App.xaml.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#region Copyright Syncfusion Inc. 2001-2019.
2+
// Copyright Syncfusion Inc. 2001-2019. All rights reserved.
3+
// Use of this code is subject to the terms of our license.
4+
// A copy of the current license can be obtained at any time by e-mailing
5+
// licensing@syncfusion.com. Any infringement will be prosecuted under
6+
// applicable laws.
7+
#endregion
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Configuration;
11+
using System.Data;
12+
using System.Linq;
13+
using System.Threading.Tasks;
14+
using System.Windows;
15+
16+
namespace Merging
17+
{
18+
/// <summary>
19+
/// Interaction logic for App.xaml
20+
/// </summary>
21+
public partial class App : Application
22+
{
23+
public App()
24+
{
25+
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(Syncfusion.Licensing.DemoCommon.FindLicenseKey());
26+
}
27+
}
28+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#region Copyright Syncfusion Inc. 2001-2019.
2+
// Copyright Syncfusion Inc. 2001-2019. All rights reserved.
3+
// Use of this code is subject to the terms of our license.
4+
// A copy of the current license can be obtained at any time by e-mailing
5+
// licensing@syncfusion.com. Any infringement will be prosecuted under
6+
// applicable laws.
7+
#endregion
8+
using Syncfusion.UI.Xaml.Grid;
9+
using Syncfusion.UI.Xaml.TreeGrid;
10+
using System.Windows.Interactivity;
11+
using System;
12+
using System.Collections.Generic;
13+
using System.Linq;
14+
using System.Text;
15+
using System.Threading.Tasks;
16+
using System.Windows;
17+
18+
namespace Merging
19+
{
20+
public delegate void TreeGridRequestTreeItemsHandler(object sender, RoutedEventArgs args);
21+
22+
/// <summary>
23+
/// Handles the cell merging in SfTreeGrid.
24+
/// </summary>
25+
public class QueryCoveredRangeBehavior : Behavior<SfTreeGrid>
26+
{
27+
/// <summary>
28+
/// Called after the behavior is attached to an AssociatedObject.
29+
/// </summary>
30+
/// <remarks>Override this to hook up functionality to the AssociatedObject.</remarks>
31+
protected override void OnAttached()
32+
{
33+
var loader= new TreeGridRequestTreeItemsHandler(AssociatedObject_Loaded);
34+
loader.Invoke(null, null);
35+
}
36+
37+
public void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
38+
{
39+
this.AssociatedObject.QueryCoveredRange += AssociatedObject_QueryCoveredRange;
40+
}
41+
42+
public void AssociatedObject_QueryCoveredRange(object sender, TreeGridQueryCoveredRangeEventArgs e)
43+
{
44+
var treeNode = this.AssociatedObject.GetNodeAtRowIndex(e.RowColumnIndex.RowIndex);
45+
if (treeNode != null && treeNode.HasChildNodes)
46+
{
47+
if (e.RowColumnIndex.ColumnIndex >= 1 && e.RowColumnIndex.ColumnIndex <= this.AssociatedObject.Columns.Count)
48+
{
49+
e.Range = new TreeGridCoveredCellInfo(0, this.AssociatedObject.Columns.Count, e.RowColumnIndex.RowIndex);
50+
e.Handled = true;
51+
}
52+
}
53+
}
54+
55+
/// <summary>
56+
/// Called when the behavior is being detached from its AssociatedObject, but before it has actually occurred.
57+
/// </summary>
58+
/// <remarks>Override this to unhook functionality from the AssociatedObject.</remarks>
59+
protected override void OnDetaching()
60+
{
61+
base.OnDetaching();
62+
this.AssociatedObject.Loaded -= AssociatedObject_Loaded;
63+
this.AssociatedObject.QueryCoveredRange -= AssociatedObject_QueryCoveredRange;
64+
}
65+
}
66+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#region Copyright Syncfusion Inc. 2001-2019.
2+
// Copyright Syncfusion Inc. 2001-2019. All rights reserved.
3+
// Use of this code is subject to the terms of our license.
4+
// A copy of the current license can be obtained at any time by e-mailing
5+
// licensing@syncfusion.com. Any infringement will be prosecuted under
6+
// applicable laws.
7+
#endregion
8+
using Merging;
9+
using Syncfusion.UI.Xaml.Grid;
10+
using Syncfusion.UI.Xaml.TreeGrid;
11+
using System;
12+
using System.Collections.Generic;
13+
using System.Linq;
14+
using System.Text;
15+
using System.Threading.Tasks;
16+
using System.Windows.Interactivity;
17+
18+
19+
namespace Merging
20+
{
21+
class RequestTreeItemsBehavior : Behavior<SfTreeGrid>
22+
{
23+
EmployeeRepository viewModel;
24+
25+
protected override void OnAttached()
26+
{
27+
base.OnAttached();
28+
viewModel = this.AssociatedObject.DataContext as EmployeeRepository;
29+
this.AssociatedObject.RequestTreeItems += AssociatedObject_RequestTreeItems;
30+
31+
}
32+
33+
void AssociatedObject_RequestTreeItems(object sender, TreeGridRequestTreeItemsEventArgs args)
34+
{
35+
if (args.ParentItem == null)
36+
{
37+
//get the root list - get all employees who have no boss
38+
args.ChildItems = EmployeeRepository.GetEmployees().Where(x => x.ReportsTo == -1); //get all employees whose boss's id is -1 (no boss)
39+
}
40+
else //if ParentItem not null, then set args.ChildList to the child items for the given ParentItem.
41+
{
42+
//get the children of the parent object
43+
Employee emp = args.ParentItem as Employee;
44+
if (emp != null)
45+
{
46+
//get all employees that report to the parent employee
47+
args.ChildItems = EmployeeRepository.GetEmployees().Where(x => x.ReportsTo == emp.Id);
48+
}
49+
}
50+
}
51+
52+
protected override void OnDetaching()
53+
{
54+
base.OnDetaching();
55+
this.AssociatedObject.RequestTreeItems -= AssociatedObject_RequestTreeItems;
56+
}
57+
}
58+
}

CellMergeDemo_2015.csproj

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{B294434E-F6E8-4DDC-911C-8175CEF9D483}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>CellMerge</RootNamespace>
11+
<AssemblyName>CellMerge</AssemblyName>
12+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
15+
<WarningLevel>4</WarningLevel>
16+
<TargetFrameworkProfile />
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<PlatformTarget>AnyCPU</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<PlatformTarget>AnyCPU</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="Syncfusion.Data.WPF">
39+
<SpecificVersion>False</SpecificVersion>
40+
</Reference>
41+
<Reference Include="Syncfusion.SampleLayout">
42+
<SpecificVersion>False</SpecificVersion>
43+
</Reference>
44+
<Reference Include="Syncfusion.SfGrid.WPF">
45+
<SpecificVersion>False</SpecificVersion>
46+
</Reference>
47+
<Reference Include="Syncfusion.Shared.Wpf">
48+
<SpecificVersion>False</SpecificVersion>
49+
</Reference>
50+
<Reference Include="Syncfusion.Linq.Base">
51+
<SpecificVersion>False</SpecificVersion>
52+
</Reference>
53+
<Reference Include="Syncfusion.Tools.WPF">
54+
<SpecificVersion>False</SpecificVersion>
55+
</Reference>
56+
<Reference Include="Syncfusion.Grid.Wpf">
57+
<SpecificVersion>False</SpecificVersion>
58+
</Reference>
59+
<Reference Include="Syncfusion.GridCommon.Wpf">
60+
<SpecificVersion>False</SpecificVersion>
61+
</Reference>
62+
<Reference Include="System" />
63+
<Reference Include="System.Data" />
64+
<Reference Include="System.Windows.Interactivity">
65+
<HintPath>..\..\..\..\..\Common\Data\Interactivity_Binaries\WPF\4.0\System.Windows.Interactivity.dll</HintPath>
66+
</Reference>
67+
<Reference Include="System.Xml" />
68+
<Reference Include="Microsoft.CSharp" />
69+
<Reference Include="System.Core" />
70+
<Reference Include="System.Xml.Linq" />
71+
<Reference Include="System.Data.DataSetExtensions" />
72+
<Reference Include="System.Xaml">
73+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
74+
</Reference>
75+
<Reference Include="WindowsBase" />
76+
<Reference Include="PresentationCore" />
77+
<Reference Include="PresentationFramework" />
78+
</ItemGroup>
79+
<ItemGroup>
80+
<ApplicationDefinition Include="App.xaml">
81+
<Generator>MSBuild:Compile</Generator>
82+
<SubType>Designer</SubType>
83+
</ApplicationDefinition>
84+
<Compile Include="Behaviors\QueryCoveredRangeBehavior.cs" />
85+
<Compile Include="Behaviors\RequestTreeItemsBehavior.cs" />
86+
<Compile Include="Helper\Converters.cs" />
87+
<Compile Include="Helper\SfTreeGridBehavior.cs" />
88+
<Compile Include="Model\EmployeeInfo.cs" />
89+
<Compile Include="ViewModel\ViewModel.cs" />
90+
<Page Include="MainWindow.xaml">
91+
<Generator>MSBuild:Compile</Generator>
92+
<SubType>Designer</SubType>
93+
</Page>
94+
<Compile Include="App.xaml.cs">
95+
<DependentUpon>App.xaml</DependentUpon>
96+
<SubType>Code</SubType>
97+
</Compile>
98+
<Compile Include="MainWindow.xaml.cs">
99+
<DependentUpon>MainWindow.xaml</DependentUpon>
100+
<SubType>Code</SubType>
101+
</Compile>
102+
</ItemGroup>
103+
<ItemGroup>
104+
<Compile Include="Properties\AssemblyInfo.cs">
105+
<SubType>Code</SubType>
106+
</Compile>
107+
<Compile Include="Properties\Resources.Designer.cs">
108+
<AutoGen>True</AutoGen>
109+
<DesignTime>True</DesignTime>
110+
<DependentUpon>Resources.resx</DependentUpon>
111+
</Compile>
112+
<Compile Include="Properties\Settings.Designer.cs">
113+
<AutoGen>True</AutoGen>
114+
<DependentUpon>Settings.settings</DependentUpon>
115+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
116+
</Compile>
117+
<EmbeddedResource Include="Properties\Resources.resx">
118+
<Generator>ResXFileCodeGenerator</Generator>
119+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
120+
</EmbeddedResource>
121+
<None Include="Properties\Settings.settings">
122+
<Generator>SettingsSingleFileGenerator</Generator>
123+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
124+
</None>
125+
<AppDesigner Include="Properties\" />
126+
</ItemGroup>
127+
<ItemGroup>
128+
<Resource Include="App.ico" />
129+
</ItemGroup>
130+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
131+
<ItemGroup>
132+
<Reference Include="Syncfusion.Licensing" />
133+
</ItemGroup>
134+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
135+
Other similar extension points exist, see Microsoft.Common.targets.
136+
<Target Name="BeforeBuild">
137+
</Target>
138+
<Target Name="AfterBuild">
139+
</Target>
140+
-->
141+
</Project>

CellMergeDemo_2015.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CellMergeDemo_2015", "CellMergeDemo_2015.csproj", "{B294434E-F6E8-4DDC-911C-8175CEF9D483}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{B294434E-F6E8-4DDC-911C-8175CEF9D483}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B294434E-F6E8-4DDC-911C-8175CEF9D483}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B294434E-F6E8-4DDC-911C-8175CEF9D483}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B294434E-F6E8-4DDC-911C-8175CEF9D483}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

Helper/Converters.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#region Copyright Syncfusion Inc. 2001-2019.
2+
// Copyright Syncfusion Inc. 2001-2019. All rights reserved.
3+
// Use of this code is subject to the terms of our license.
4+
// A copy of the current license can be obtained at any time by e-mailing
5+
// licensing@syncfusion.com. Any infringement will be prosecuted under
6+
// applicable laws.
7+
#endregion
8+
using Syncfusion.UI.Xaml.Grid;
9+
using System;
10+
using System.Collections.Generic;
11+
using System.Linq;
12+
using System.Text;
13+
using System.Threading.Tasks;
14+
using System.Windows.Data;
15+
16+
namespace Merging
17+
{
18+
internal class EditTriggerOptionConverter : IValueConverter
19+
{
20+
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
21+
{
22+
int? index = value as int?;
23+
if (index == 0)
24+
return EditTrigger.OnTap;
25+
else
26+
return EditTrigger.OnDoubleTap;
27+
}
28+
29+
public object ConvertBack(object value, Type targetType, object parameter,
30+
System.Globalization.CultureInfo culture)
31+
{
32+
throw new NotImplementedException();
33+
}
34+
}
35+
36+
internal class CurrencyFormatConverter : IValueConverter
37+
{
38+
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
39+
{
40+
return String.Format("{0:C}", value);
41+
}
42+
43+
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
44+
{
45+
throw new NotImplementedException();
46+
}
47+
}
48+
49+
}

0 commit comments

Comments
 (0)