Skip to content

Commit 48e5275

Browse files
ES-857662 - KB for display the RowIndex in GridRowHeaderCell when combined with SfDatapager in WPF DataGrid
1 parent 27d0be4 commit 48e5275

14 files changed

Lines changed: 715 additions & 0 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="Syncfusion.Data.WPF" publicKeyToken="3d67ed1f87d44c89" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-24.1460.29.0" newVersion="24.1460.29.0" />
11+
</dependentAssembly>
12+
</assemblyBinding>
13+
</runtime>
14+
</configuration>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="DisplayRowIndexinRowheadercell.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:DisplayRowIndexinRowheadercell"
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 DisplayRowIndexinRowheadercell
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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>{73B73DCA-91FF-40D9-97D0-E37221C16C62}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>DisplayRowIndexinRowheadercell</RootNamespace>
10+
<AssemblyName>DisplayRowIndexinRowheadercell</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="Syncfusion.Data.WPF, Version=24.1460.29.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
39+
<HintPath>packages\Syncfusion.Data.WPF.24.1.29\lib\net46\Syncfusion.Data.WPF.dll</HintPath>
40+
</Reference>
41+
<Reference Include="Syncfusion.Licensing, Version=23.2460.5.0, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL">
42+
<HintPath>packages\Syncfusion.Licensing.23.2.5\lib\net46\Syncfusion.Licensing.dll</HintPath>
43+
</Reference>
44+
<Reference Include="Syncfusion.SfGrid.WPF, Version=23.2460.5.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
45+
<HintPath>packages\Syncfusion.SfGrid.WPF.23.2.5\lib\net46\Syncfusion.SfGrid.WPF.dll</HintPath>
46+
</Reference>
47+
<Reference Include="Syncfusion.Shared.WPF, Version=23.2460.5.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
48+
<HintPath>packages\Syncfusion.Shared.WPF.23.2.5\lib\net46\Syncfusion.Shared.WPF.dll</HintPath>
49+
</Reference>
50+
<Reference Include="System" />
51+
<Reference Include="System.Data" />
52+
<Reference Include="System.Xml" />
53+
<Reference Include="Microsoft.CSharp" />
54+
<Reference Include="System.Core" />
55+
<Reference Include="System.Xml.Linq" />
56+
<Reference Include="System.Data.DataSetExtensions" />
57+
<Reference Include="System.Net.Http" />
58+
<Reference Include="System.Xaml">
59+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
60+
</Reference>
61+
<Reference Include="WindowsBase" />
62+
<Reference Include="PresentationCore" />
63+
<Reference Include="PresentationFramework" />
64+
</ItemGroup>
65+
<ItemGroup>
66+
<ApplicationDefinition Include="App.xaml">
67+
<Generator>MSBuild:Compile</Generator>
68+
<SubType>Designer</SubType>
69+
</ApplicationDefinition>
70+
<Compile Include="ViewModel\OrderInfoViewModel.cs" />
71+
<Page Include="MainWindow.xaml">
72+
<Generator>MSBuild:Compile</Generator>
73+
<SubType>Designer</SubType>
74+
</Page>
75+
<Compile Include="App.xaml.cs">
76+
<DependentUpon>App.xaml</DependentUpon>
77+
<SubType>Code</SubType>
78+
</Compile>
79+
<Compile Include="MainWindow.xaml.cs">
80+
<DependentUpon>MainWindow.xaml</DependentUpon>
81+
<SubType>Code</SubType>
82+
</Compile>
83+
</ItemGroup>
84+
<ItemGroup>
85+
<Compile Include="Model\OrderInfo.cs" />
86+
<Compile Include="Properties\AssemblyInfo.cs">
87+
<SubType>Code</SubType>
88+
</Compile>
89+
<Compile Include="Properties\Resources.Designer.cs">
90+
<AutoGen>True</AutoGen>
91+
<DesignTime>True</DesignTime>
92+
<DependentUpon>Resources.resx</DependentUpon>
93+
</Compile>
94+
<Compile Include="Properties\Settings.Designer.cs">
95+
<AutoGen>True</AutoGen>
96+
<DependentUpon>Settings.settings</DependentUpon>
97+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
98+
</Compile>
99+
<EmbeddedResource Include="Properties\Resources.resx">
100+
<Generator>ResXFileCodeGenerator</Generator>
101+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
102+
</EmbeddedResource>
103+
<None Include="packages.config" />
104+
<None Include="Properties\Settings.settings">
105+
<Generator>SettingsSingleFileGenerator</Generator>
106+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
107+
</None>
108+
</ItemGroup>
109+
<ItemGroup>
110+
<None Include="App.config" />
111+
</ItemGroup>
112+
<ItemGroup />
113+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
114+
</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.34009.444
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DisplayRowIndexinRowheadercell", "DisplayRowIndexinRowheadercell.csproj", "{73B73DCA-91FF-40D9-97D0-E37221C16C62}"
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+
{73B73DCA-91FF-40D9-97D0-E37221C16C62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{73B73DCA-91FF-40D9-97D0-E37221C16C62}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{73B73DCA-91FF-40D9-97D0-E37221C16C62}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{73B73DCA-91FF-40D9-97D0-E37221C16C62}.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 = {89303195-327C-4C6A-BB87-69B5E404B72E}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<Window x:Class="DisplayRowIndexinRowheadercell.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:local="clr-namespace:DisplayRowIndexinRowheadercell"
9+
mc:Ignorable="d"
10+
Title="MainWindow" Height="450" Width="800">
11+
12+
13+
14+
<Window.DataContext>
15+
<local:Order/>
16+
</Window.DataContext>
17+
18+
<Window.Resources>
19+
<local:PageConverter x:Key="converter"/>
20+
</Window.Resources>
21+
22+
<Grid x:Name="Root_Grid">
23+
<Grid.RowDefinitions>
24+
<RowDefinition Height="*" />
25+
<RowDefinition Height="Auto" />
26+
</Grid.RowDefinitions>
27+
<syncfusion:SfDataGrid x:Name="dataGrid"
28+
AllowFiltering="True"
29+
ItemsSource="{Binding ElementName=sfDataPager,Path=PagedSource}"
30+
ShowRowHeader="True">
31+
32+
<syncfusion:SfDataGrid.Resources>
33+
34+
<Style TargetType="syncfusion:GridRowHeaderCell">
35+
<Setter Property="Template">
36+
<Setter.Value>
37+
<ControlTemplate TargetType="syncfusion:GridRowHeaderCell">
38+
<Border x:Name="PART_RowHeaderCellBorder"
39+
Background="Blue"
40+
BorderBrush="{TemplateBinding BorderBrush}"
41+
BorderThickness="{TemplateBinding BorderThickness}">
42+
<Grid>
43+
<!--//RowIndex is displayed here-->
44+
<TextBlock HorizontalAlignment="Center"
45+
VerticalAlignment="Center"
46+
Foreground="White"
47+
TextAlignment="Center" >
48+
<TextBlock.Text>
49+
<MultiBinding Converter="{StaticResource converter}" >
50+
<Binding Path="RowIndex" RelativeSource="{RelativeSource TemplatedParent}"/>
51+
<Binding ElementName="dataGrid" />
52+
<Binding ElementName="sfDataPager" />
53+
</MultiBinding>
54+
</TextBlock.Text>
55+
</TextBlock>
56+
</Grid>
57+
</Border>
58+
</ControlTemplate>
59+
</Setter.Value>
60+
</Setter>
61+
</Style>
62+
</syncfusion:SfDataGrid.Resources>
63+
</syncfusion:SfDataGrid>
64+
65+
<datapager:SfDataPager x:Name="sfDataPager"
66+
Grid.Row="1"
67+
NumericButtonCount="10"
68+
PageSize="10"
69+
Source="{Binding Orders}" />
70+
71+
</Grid>
72+
</Window>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 DisplayRowIndexinRowheadercell
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+
sfDataPager.PageIndexChanged += SfDataPager_PageIndexChanged;
30+
31+
}
32+
33+
private void SfDataPager_PageIndexChanged(object sender, PageIndexChangedEventArgs e)
34+
{
35+
for (int i = 1; i < dataGrid.RowGenerator.Items.Count; i++)
36+
{
37+
var rowHeaderCell = ((dataGrid.RowGenerator.Items[i] as DataRow).VisibleColumns[0] as DataColumn).ColumnElement;
38+
(rowHeaderCell as GridRowHeaderCell).RowIndex = -1;
39+
}
40+
}
41+
}
42+
43+
public class PageConverter : IMultiValueConverter
44+
{
45+
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
46+
{
47+
var dataPager = values[2] as SfDataPager;
48+
49+
if (dataPager.PageIndex == 0 || (int)values[0] == -1)
50+
{
51+
return values[0].ToString();
52+
}
53+
54+
values[0] = (int)values[0] + (((dataPager.PageIndex + 1) - 1) * dataPager.PageSize);
55+
return values[0].ToString();
56+
57+
}
58+
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
59+
{
60+
throw new NotImplementedException();
61+
}
62+
}
63+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace DisplayRowIndexinRowheadercell
8+
{
9+
public class OrderInfo
10+
{
11+
int orderID;
12+
string customerId;
13+
string country;
14+
string customerName;
15+
string shippingCity;
16+
17+
public int OrderID
18+
{
19+
get { return orderID; }
20+
set { orderID = value; }
21+
}
22+
23+
public string CustomerID
24+
{
25+
get { return customerId; }
26+
set { customerId = value; }
27+
}
28+
29+
public string CustomerName
30+
{
31+
get { return customerName; }
32+
set { customerName = value; }
33+
}
34+
35+
public string Country
36+
{
37+
get { return country; }
38+
set { country = value; }
39+
}
40+
41+
public string ShipCity
42+
{
43+
get { return shippingCity; }
44+
set { shippingCity = value; }
45+
}
46+
47+
public OrderInfo(int orderId, string customerName, string country, string customerId, string shipCity)
48+
{
49+
this.OrderID = orderId;
50+
this.CustomerName = customerName;
51+
this.Country = country;
52+
this.CustomerID = customerId;
53+
this.ShipCity = shipCity;
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)