Skip to content

Commit 6671408

Browse files
How to change the column resizing cursor position in WPF DataGrid(SfDataGrid)?
1 parent 0cb09ad commit 6671408

14 files changed

+685
-0
lines changed

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

SfDataGridDemo/App.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="SfDataGrid_MVVM.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:SfDataGrid_MVVM"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>

SfDataGridDemo/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 SfDataGrid_MVVM
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}

SfDataGridDemo/MainWindow.xaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<Window x:Class="SfDataGrid_MVVM.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:SfDataGrid_MVVM"
7+
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
8+
mc:Ignorable="d"
9+
Title="MainWindow" Height="450" Width="800">
10+
<Window.DataContext>
11+
<local:ViewModel />
12+
</Window.DataContext>
13+
<Grid>
14+
<syncfusion:SfDataGrid Name="dataGrid"
15+
AutoGenerateColumns="False"
16+
AllowEditing="True"
17+
GridValidationMode="InView"
18+
ColumnSizer="Auto"
19+
ItemsSource="{Binding Employees}"
20+
AllowFiltering="True"
21+
AllowResizingColumns="True"
22+
AllowDrop="True"
23+
>
24+
<syncfusion:SfDataGrid.Columns>
25+
<syncfusion:GridTextColumn MappingName="FirstName" HeaderText="First Name" />
26+
<syncfusion:GridTextColumn MappingName="LastName" HeaderText="Last Name" />
27+
<syncfusion:GridTextColumn MappingName="ID" HeaderText="ID"/>
28+
<syncfusion:GridTextColumn MappingName="Title" HeaderText="Title"/>
29+
<syncfusion:GridCurrencyColumn MappingName="Salary" HeaderText="Salary" />
30+
<syncfusion:GridTextColumn MappingName="ReportsTo" HeaderText="Reports To" />
31+
</syncfusion:SfDataGrid.Columns>
32+
<syncfusion:SfDataGrid.LayoutTransform>
33+
<TransformGroup>
34+
<RotateTransform Angle="-90"/>
35+
</TransformGroup>
36+
</syncfusion:SfDataGrid.LayoutTransform>
37+
</syncfusion:SfDataGrid>
38+
</Grid>
39+
40+
</Window>

SfDataGridDemo/MainWindow.xaml.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Syncfusion.UI.Xaml.TreeGrid;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Data;
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 SfDataGrid_MVVM
19+
{
20+
/// <summary>
21+
/// Interaction logic for MainWindow.xaml
22+
/// </summary>
23+
public partial class MainWindow : Window
24+
{
25+
public MainWindow()
26+
{
27+
InitializeComponent();
28+
this.dataGrid.ColumnResizingController.ResizingCursor = Cursors.SizeNS;
29+
}
30+
}
31+
}

SfDataGridDemo/Model.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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 SfDataGrid_MVVM
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+
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+
public int ID
35+
{
36+
get { return _id; }
37+
set { _id = value; }
38+
}
39+
40+
public string Title
41+
{
42+
get { return _title; }
43+
set { _title = value; }
44+
}
45+
46+
public decimal Salary
47+
{
48+
get { return _salary; }
49+
set { _salary = value; }
50+
}
51+
52+
public int ReportsTo
53+
{
54+
get { return _reportsTo; }
55+
set { _reportsTo = value; }
56+
}
57+
58+
[Display(AutoGenerateField = false)]
59+
60+
public string Error => string.Empty;
61+
62+
public string this[string columnName]
63+
{
64+
get
65+
{
66+
string errorMessage = string.Empty;
67+
if (!columnName.Equals("Salary"))
68+
return string.Empty;
69+
if (this.Salary < 30000)
70+
errorMessage+= "The 'Salary'should be less than 30000" ;
71+
if (this.Salary == 0)
72+
errorMessage += "\nThe 'Salary'should have some values";
73+
74+
return errorMessage;
75+
}
76+
}
77+
78+
[Display(AutoGenerateField = false)]
79+
80+
public bool HasErrors
81+
{
82+
get
83+
{
84+
return false;
85+
}
86+
}
87+
88+
private List<string> errors = new List<string>();
89+
public IEnumerable GetErrors(string propertyName)
90+
{
91+
return errors;
92+
}
93+
}
94+
}
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("SfDataGrid_MVVM")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("")]
14+
[assembly: AssemblyProduct("SfDataGrid_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")]

SfDataGridDemo/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)