Skip to content

Commit 026f7fa

Browse files
Merge pull request #1 from vijayarasan/master
How to use the editing related events in GridCheckBoxColumn of WinUI DataGrid (SfDataGrid)?
2 parents 3b54a43 + b1c09ac commit 026f7fa

22 files changed

+556
-1
lines changed

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
11
# How to use the editing related events in GridCheckBoxColumn of WinUI DataGrid (SfDataGrid)?
2-
This example illustrates how to use the editing related events in GridCheckBoxColumn of WinUI DataGrid (SfDataGrid).
2+
3+
The **BeginEdit** and **EndEdit** events are not triggered when you check or uncheck the CheckBox control in [GridCheckBoxColumn](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.GridCheckBoxColumn.html) in [WinUI DataGrid](https://www.syncfusion.com/winui-controls/datagrid) (SfDataGrid). However, you can get the notification while changing the CheckBox state by using the [CurrentCellValueChanged](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.SfDataGrid.html#Syncfusion_UI_Xaml_DataGrid_SfDataGrid_CurrentCellValueChanged) event.
4+
5+
```C#
6+
7+
//Event subscription
8+
this.dataGrid.CurrentCellValueChanged += OnCurrentCellValueChanged;
9+
10+
//Event customization
11+
public void OnCurrentCellValueChanged(object sender, CurrentCellValueChangedEventArgs args)
12+
{
13+
int columnindex = dataGrid.ResolveToGridVisibleColumnIndex(args.RowColumnIndex.ColumnIndex);
14+
15+
if (columnindex < 0)
16+
return;
17+
18+
var column = dataGrid.Columns[columnindex];
19+
20+
if (column is GridCheckBoxColumn)
21+
{
22+
var rowIndex = this.dataGrid.ResolveToRecordIndex(args.RowColumnIndex.RowIndex);
23+
24+
if (rowIndex < 0)
25+
return;
26+
27+
RecordEntry record = null;
28+
29+
if (this.dataGrid.View != null)
30+
{
31+
if (this.dataGrid.View.TopLevelGroup != null)
32+
{
33+
//Get the record when grouping applied in SfDataGrid
34+
record = (this.dataGrid.View.TopLevelGroup.DisplayElements[rowIndex] as RecordEntry);
35+
}
36+
else
37+
{
38+
record = this.dataGrid.View.Records[rowIndex] as RecordEntry;
39+
}
40+
41+
if (record != null)
42+
{
43+
//Checkbox property changed value is stored here.
44+
var value = (record.Data as OrderInfo).Review;
45+
}
46+
}
47+
}
48+
}
49+
50+
```
51+
52+
Take a moment to peruse the [WinUI DataGrid - Column Types](https://help.syncfusion.com/winui/datagrid/column-types) documentation, to learn more about column types with code examples.

SfDataGridDemo/App.xaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!-- Copyright (c) Microsoft Corporation and Contributors. -->
2+
<!-- Licensed under the MIT License. -->
3+
4+
<Application
5+
x:Class="DataGridDemo.App"
6+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
7+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
8+
xmlns:local="using:DataGridDemo">
9+
<Application.Resources>
10+
<ResourceDictionary>
11+
<ResourceDictionary.MergedDictionaries>
12+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
13+
<!-- Other merged dictionaries here -->
14+
</ResourceDictionary.MergedDictionaries>
15+
<!-- Other app resources here -->
16+
</ResourceDictionary>
17+
</Application.Resources>
18+
</Application>

SfDataGridDemo/App.xaml.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Microsoft.UI.Xaml;
2+
3+
// To learn more about WinUI, the WinUI project structure,
4+
// and more about our project templates, see: http://aka.ms/winui-project-info.
5+
6+
namespace DataGridDemo
7+
{
8+
/// <summary>
9+
/// Provides application-specific behavior to supplement the default Application class.
10+
/// </summary>
11+
public partial class App : Application
12+
{
13+
/// <summary>
14+
/// Initializes the singleton application object. This is the first line of authored code
15+
/// executed, and as such is the logical equivalent of main() or WinMain().
16+
/// </summary>
17+
public App()
18+
{
19+
this.InitializeComponent();
20+
}
21+
22+
/// <summary>
23+
/// Invoked when the application is launched.
24+
/// </summary>
25+
/// <param name="args">Details about the launch request and process.</param>
26+
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
27+
{
28+
m_window = new MainWindow();
29+
m_window.Activate();
30+
}
31+
32+
private Window m_window;
33+
}
34+
}
432 Bytes
Loading
5.25 KB
Loading
1.71 KB
Loading
637 Bytes
Loading
283 Bytes
Loading
456 Bytes
Loading
2.05 KB
Loading

0 commit comments

Comments
 (0)