Skip to content

Commit 8509a62

Browse files
Merge pull request #1 from SyncfusionExamples/ES-857662---RowHeaderKB
ES-857662 - KB for display the RowIndex in GridRowHeaderCell when combined with SfDatapager in WPF DataGrid
2 parents 27d0be4 + ea22bcf commit 8509a62

23 files changed

+3201
-2
lines changed
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>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="DisplayRowIndexInGridRowHeaderCell.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:DisplayRowIndexInGridRowHeaderCell"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
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 DisplayRowIndexInGridRowHeaderCell
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Microsoft.Xaml.Behaviors;
2+
using Syncfusion.UI.Xaml.Controls.DataPager;
3+
using Syncfusion.UI.Xaml.Grid;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows;
10+
using System.Windows.Controls;
11+
12+
namespace DisplayRowIndexInGridRowHeaderCell
13+
{
14+
internal class WindowBehavior : Behavior<Window>
15+
{
16+
17+
SfDataPager dataPager;
18+
SfDataGrid dataGrid;
19+
protected override void OnAttached()
20+
{
21+
base.OnAttached();
22+
var window = this.AssociatedObject as Window;
23+
dataGrid = window.FindName("dataGrid") as SfDataGrid;
24+
dataPager = window.FindName("dataPager") as SfDataPager;
25+
dataPager.PageIndexChanged += OnPageIndexChanged;
26+
}
27+
28+
private void OnPageIndexChanged(object sender, PageIndexChangedEventArgs e)
29+
{
30+
for (int i = 1; i < dataGrid.RowGenerator.Items.Count; i++)
31+
{
32+
var rowHeaderCell = ((dataGrid.RowGenerator.Items[i] as DataRow).VisibleColumns[0] as DataColumn).ColumnElement;
33+
(rowHeaderCell as GridRowHeaderCell).RowIndex = -1;
34+
}
35+
}
36+
37+
protected override void OnDetaching()
38+
{
39+
dataPager.PageIndexChanged -= OnPageIndexChanged;
40+
base.OnDetaching();
41+
}
42+
}
43+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Syncfusion.UI.Xaml.Controls.DataPager;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Globalization;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows.Data;
9+
10+
namespace DisplayRowIndexInGridRowHeaderCell
11+
{
12+
public class RowIndexConverter : IMultiValueConverter
13+
{
14+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
15+
{
16+
var dataPager = values[2] as SfDataPager;
17+
18+
if (dataPager.PageIndex == 0 || (int)values[0] == -1)
19+
{
20+
return values[0].ToString();
21+
}
22+
23+
values[0] = (int)values[0] + (((dataPager.PageIndex + 1) - 1) * dataPager.PageSize);
24+
return values[0].ToString();
25+
26+
}
27+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
28+
{
29+
throw new NotImplementedException();
30+
}
31+
}
32+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" 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>{212CC225-D3A4-4CED-B9AC-9CF1C1593B89}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>DisplayRowIndexInGridRowHeaderCell</RootNamespace>
10+
<AssemblyName>DisplayRowIndexInGridRowHeaderCell</AssemblyName>
11+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<WarningLevel>4</WarningLevel>
15+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
16+
<Deterministic>true</Deterministic>
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="Microsoft.Xaml.Behaviors, Version=1.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
39+
<HintPath>packages\Microsoft.Xaml.Behaviors.Wpf.1.0.1\lib\net45\Microsoft.Xaml.Behaviors.dll</HintPath>
40+
</Reference>
41+
<Reference Include="Syncfusion.Data.WPF" />
42+
<Reference Include="Syncfusion.SfGrid.WPF" />
43+
<Reference Include="Syncfusion.Shared.WPF" />
44+
<Reference Include="System" />
45+
<Reference Include="System.Data" />
46+
<Reference Include="System.Xml" />
47+
<Reference Include="Microsoft.CSharp" />
48+
<Reference Include="System.Core" />
49+
<Reference Include="System.Xml.Linq" />
50+
<Reference Include="System.Data.DataSetExtensions" />
51+
<Reference Include="System.Net.Http" />
52+
<Reference Include="System.Xaml">
53+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
54+
</Reference>
55+
<Reference Include="WindowsBase" />
56+
<Reference Include="PresentationCore" />
57+
<Reference Include="PresentationFramework" />
58+
</ItemGroup>
59+
<ItemGroup>
60+
<ApplicationDefinition Include="App.xaml">
61+
<Generator>MSBuild:Compile</Generator>
62+
<SubType>Designer</SubType>
63+
</ApplicationDefinition>
64+
<Compile Include="Behavior\WindowBehavior.cs" />
65+
<Compile Include="Converter\RowIndexConverter.cs" />
66+
<Compile Include="ViewModel\ViewModel.cs" />
67+
<Page Include="MainWindow.xaml">
68+
<Generator>MSBuild:Compile</Generator>
69+
<SubType>Designer</SubType>
70+
</Page>
71+
<Compile Include="App.xaml.cs">
72+
<DependentUpon>App.xaml</DependentUpon>
73+
<SubType>Code</SubType>
74+
</Compile>
75+
<Compile Include="MainWindow.xaml.cs">
76+
<DependentUpon>MainWindow.xaml</DependentUpon>
77+
<SubType>Code</SubType>
78+
</Compile>
79+
</ItemGroup>
80+
<ItemGroup>
81+
<Compile Include="Model\OrderInfo.cs" />
82+
<Compile Include="Properties\AssemblyInfo.cs">
83+
<SubType>Code</SubType>
84+
</Compile>
85+
<Compile Include="Properties\Resources.Designer.cs">
86+
<AutoGen>True</AutoGen>
87+
<DesignTime>True</DesignTime>
88+
<DependentUpon>Resources.resx</DependentUpon>
89+
</Compile>
90+
<Compile Include="Properties\Settings.Designer.cs">
91+
<AutoGen>True</AutoGen>
92+
<DependentUpon>Settings.settings</DependentUpon>
93+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
94+
</Compile>
95+
<EmbeddedResource Include="Properties\Resources.resx">
96+
<Generator>ResXFileCodeGenerator</Generator>
97+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
98+
</EmbeddedResource>
99+
<None Include="packages.config" />
100+
<None Include="Properties\Settings.settings">
101+
<Generator>SettingsSingleFileGenerator</Generator>
102+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
103+
</None>
104+
</ItemGroup>
105+
<ItemGroup>
106+
<None Include="App.config" />
107+
</ItemGroup>
108+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
109+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.7.34221.43
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DisplayRowIndexInGridRowHeaderCell", "DisplayRowIndexInGridRowHeaderCell.csproj", "{212CC225-D3A4-4CED-B9AC-9CF1C1593B89}"
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+
{212CC225-D3A4-4CED-B9AC-9CF1C1593B89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{212CC225-D3A4-4CED-B9AC-9CF1C1593B89}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{212CC225-D3A4-4CED-B9AC-9CF1C1593B89}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{212CC225-D3A4-4CED-B9AC-9CF1C1593B89}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {96607B63-364F-4226-87AC-8EF591EB2565}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<Window x:Class="DisplayRowIndexInGridRowHeaderCell.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:syncfusion="http://schemas.syncfusion.com/wpf"
6+
xmlns:datapager="clr-namespace:Syncfusion.UI.Xaml.Controls.DataPager;assembly=Syncfusion.SfGrid.WPF"
7+
xmlns:interactivity="http://schemas.microsoft.com/xaml/behaviors"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:local="clr-namespace:DisplayRowIndexInGridRowHeaderCell"
10+
mc:Ignorable="d"
11+
Title="MainWindow" Height="450" Width="800">
12+
13+
14+
15+
<Window.DataContext>
16+
<local:ViewModel/>
17+
</Window.DataContext>
18+
19+
<Window.Resources>
20+
<local:RowIndexConverter x:Key="rowIndexConverter"/>
21+
</Window.Resources>
22+
23+
<Grid x:Name="Root_Grid">
24+
<Grid.RowDefinitions>
25+
<RowDefinition Height="auto" />
26+
<RowDefinition Height="Auto" />
27+
</Grid.RowDefinitions>
28+
<syncfusion:SfDataGrid x:Name="dataGrid"
29+
AllowFiltering="True"
30+
Margin="10"
31+
ColumnSizer="Star"
32+
AutoGenerateColumns="False"
33+
ItemsSource="{Binding ElementName=dataPager,Path=PagedSource}"
34+
ShowRowHeader="True">
35+
<syncfusion:SfDataGrid.Columns>
36+
<syncfusion:GridNumericColumn HeaderText="Order ID" MappingName="OrderID" NumberDecimalDigits="0"/>
37+
<syncfusion:GridTextColumn HeaderText="Customer ID" MappingName="CustomerID"/>
38+
<syncfusion:GridTextColumn HeaderText="Customer Name" MappingName="CustomerName"/>
39+
<syncfusion:GridTextColumn MappingName="Country"/>
40+
</syncfusion:SfDataGrid.Columns>
41+
42+
<syncfusion:SfDataGrid.Resources>
43+
<Style TargetType="syncfusion:GridRowHeaderCell">
44+
<Setter Property="Template">
45+
<Setter.Value>
46+
<ControlTemplate TargetType="syncfusion:GridRowHeaderCell">
47+
<Border x:Name="PART_RowHeaderCellBorder"
48+
Background="Blue"
49+
BorderBrush="{TemplateBinding BorderBrush}"
50+
BorderThickness="{TemplateBinding BorderThickness}">
51+
<Grid>
52+
<!--//RowIndex is displayed here-->
53+
<TextBlock HorizontalAlignment="Center"
54+
VerticalAlignment="Center"
55+
Foreground="White"
56+
TextAlignment="Center" >
57+
<TextBlock.Text>
58+
<MultiBinding Converter="{StaticResource rowIndexConverter}" >
59+
<Binding Path="RowIndex" RelativeSource="{RelativeSource TemplatedParent}"/>
60+
<Binding ElementName="dataGrid" />
61+
<Binding ElementName="dataPager" />
62+
</MultiBinding>
63+
</TextBlock.Text>
64+
</TextBlock>
65+
</Grid>
66+
</Border>
67+
</ControlTemplate>
68+
</Setter.Value>
69+
</Setter>
70+
</Style>
71+
</syncfusion:SfDataGrid.Resources>
72+
</syncfusion:SfDataGrid>
73+
74+
<datapager:SfDataPager x:Name="dataPager"
75+
Grid.Row="1"
76+
NumericButtonCount="10"
77+
PageSize="10"
78+
Source="{Binding Orders}" />
79+
80+
</Grid>
81+
<interactivity:Interaction.Behaviors>
82+
<local:WindowBehavior/>
83+
</interactivity:Interaction.Behaviors>
84+
</Window>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Syncfusion.UI.Xaml.Controls.DataPager;
2+
using Syncfusion.UI.Xaml.Grid;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Globalization;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows;
10+
using System.Windows.Controls;
11+
using System.Windows.Data;
12+
using System.Windows.Documents;
13+
using System.Windows.Input;
14+
using System.Windows.Media;
15+
using System.Windows.Media.Imaging;
16+
using System.Windows.Navigation;
17+
using System.Windows.Shapes;
18+
19+
namespace DisplayRowIndexInGridRowHeaderCell
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+
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)