Skip to content

Commit e31fae2

Browse files
Merge pull request #1 from SyncfusionExamples/rowHeight
How to refresh the row height programmatically in .NET MAUI DataGrid (SfDataGrid) ?
2 parents 49cc39b + 82dc3e1 commit e31fae2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+9604
-2
lines changed

README.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,60 @@
1-
# How-to-refresh-the-row-height-programmatically-in-.NET-MAUI-DataGrid--SfDataGrid-
2-
This demo shows how to refresh the row height programmatically in .NET MAUI DataGrid (SfDataGrid) ?
1+
# How to refresh the row height programmatically in .NET MAUI DataGrid (SfDataGrid) ?
2+
In this article, we will show you how to refresh the row height programmatically in [.NET MAUI DataGrid](https://www.syncfusion.com/maui-controls/maui-datagrid).
3+
4+
## xaml
5+
```
6+
<ContentPage.BindingContext>
7+
<local:EmployeeViewModel x:Name="viewModel" />
8+
</ContentPage.BindingContext>
9+
10+
<syncfusion:SfDataGrid x:Name="sfGrid"
11+
GridLinesVisibility="Both"
12+
HeaderGridLinesVisibility="Both"
13+
AutoGenerateColumnsMode="None"
14+
QueryRowHeight="sfGrid_QueryRowHeight"
15+
ItemsSource="{Binding Employees}">
16+
17+
<syncfusion:SfDataGrid.Columns>
18+
<syncfusion:DataGridNumericColumn MappingName="EmployeeID"
19+
Format="#"
20+
HeaderText="Employee ID" />
21+
<syncfusion:DataGridTextColumn MappingName="Name"
22+
HeaderText="Employee Name" />
23+
<syncfusion:DataGridTextColumn MappingName="Title"
24+
HeaderText="Designation" />
25+
<syncfusion:DataGridDateColumn MappingName="HireDate"
26+
HeaderText="Hire Date" />
27+
28+
</syncfusion:SfDataGrid.Columns>
29+
30+
</syncfusion:SfDataGrid>
31+
```
32+
33+
## Xaml.cs
34+
The code below demonstrates how to refresh the row height programmatically in the QueryRowHeight event of SfDataGrid.
35+
```
36+
private void sfGrid_QueryRowHeight(object sender, Syncfusion.Maui.DataGrid.DataGridQueryRowHeightEventArgs e)
37+
{
38+
if (e.RowIndex > 0)
39+
{
40+
e.Height = e.GetIntrinsicRowHeight(e.RowIndex);
41+
e.Handled = true;
42+
(sender as SfDataGrid).InvalidateRowHeight(e.RowIndex, true);
43+
}
44+
}
45+
```
46+
47+
<img src="https://support.syncfusion.com/kb/agent/attachment/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjM1ODMxIiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5zeW5jZnVzaW9uLmNvbSJ9.xZVPkjhEEs9zD1jeqE_bzi53n_rgQmeN5v6okG8A1Mg" width=700/>
48+
49+
[View sample in GitHub](https://github.com/SyncfusionExamples/How-to-refresh-the-row-height-programmatically-in-.NET-MAUI-DataGrid--SfDataGrid-)
50+
51+
Take a moment to explore this [documentation](https://help.syncfusion.com/maui/datagrid/overview), where you can find more information about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this [link](https://www.syncfusion.com/maui-controls/maui-datagrid) to learn about the essential features of Syncfusion .NET MAUI DataGrid (SfDataGrid).
52+
53+
##### Conclusion
54+
55+
I hope you enjoyed learning about how to refresh the row height programmatically in the .NET MAUI DataGrid (SfDataGrid).
56+
57+
You can refer to our [.NET MAUI DataGrid’s feature tour](https://www.syncfusion.com/maui-controls/maui-datagrid) page to learn about its other groundbreaking feature representations. You can also explore our [.NET MAUI DataGrid Documentation](https://help.syncfusion.com/maui/datagrid/getting-started) to understand how to present and manipulate data.
58+
For current customers, you can check out our .NET MAUI components on the [License and Downloads](https://www.syncfusion.com/sales/teamlicense) page. If you are new to Syncfusion, you can try our 30-day [free trial](https://www.syncfusion.com/downloads/maui) to explore our .NET MAUI DataGrid and other .NET MAUI components.
59+
60+
If you have any queries or require clarifications, please let us know in the comments below. You can also contact us through our [support forums](https://www.syncfusion.com/forums), [Direct-Trac](https://support.syncfusion.com/create) or [feedback portal](https://www.syncfusion.com/feedback/maui?control=sfdatagrid), or the feedback portal. We are always happy to assist you!
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 Version 17
4+
VisualStudioVersion = 17.12.35506.116 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SfDataGridSample", "SfDataGridSample\SfDataGridSample.csproj", "{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}"
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+
{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
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+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:SfDataGridSample"
5+
x:Class="SfDataGridSample.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace SfDataGridSample
2+
{
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
}
9+
10+
protected override Window CreateWindow(IActivationState? activationState)
11+
{
12+
return new Window(new AppShell());
13+
}
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="SfDataGridSample.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:SfDataGridSample"
7+
Shell.FlyoutBehavior="Flyout"
8+
Title="SfDataGridSample">
9+
10+
<ShellContent
11+
Title="Home"
12+
ContentTemplate="{DataTemplate local:MainPage}"
13+
Route="MainPage" />
14+
15+
</Shell>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace SfDataGridSample
2+
{
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
10+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Syncfusion.Maui.DataGrid;
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+
9+
namespace SfDataGridSample
10+
{
11+
public class ColorConverter : IValueConverter
12+
{
13+
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo info)
14+
{
15+
var dataGridRow = value as DataGridRow;
16+
var rowData = dataGridRow.DataRow.RowData;
17+
if ((rowData as Employee).EmployeeID == 1005)
18+
return Colors.LightBlue;
19+
else
20+
return Colors.White;
21+
}
22+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
23+
{
24+
throw new NotImplementedException();
25+
}
26+
}
27+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid"
5+
xmlns:local="clr-namespace:SfDataGridSample"
6+
x:Class="SfDataGridSample.MainPage">
7+
8+
<ContentPage.BindingContext>
9+
<local:EmployeeViewModel x:Name="viewModel" />
10+
</ContentPage.BindingContext>
11+
12+
<syncfusion:SfDataGrid x:Name="sfGrid"
13+
GridLinesVisibility="Both"
14+
HeaderGridLinesVisibility="Both"
15+
AutoGenerateColumnsMode="None"
16+
QueryRowHeight="sfGrid_QueryRowHeight"
17+
ItemsSource="{Binding Employees}">
18+
19+
<syncfusion:SfDataGrid.Columns>
20+
<syncfusion:DataGridNumericColumn MappingName="EmployeeID"
21+
Format="#"
22+
HeaderText="Employee ID" />
23+
<syncfusion:DataGridTextColumn MappingName="Name"
24+
HeaderText="Employee Name" />
25+
<syncfusion:DataGridTextColumn MappingName="Title"
26+
HeaderText="Designation" />
27+
<syncfusion:DataGridDateColumn MappingName="HireDate"
28+
HeaderText="Hire Date" />
29+
30+
</syncfusion:SfDataGrid.Columns>
31+
32+
</syncfusion:SfDataGrid>
33+
34+
</ContentPage>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Syncfusion.Maui.DataGrid;
2+
using Syncfusion.Maui.DataGrid.Helper;
3+
using System.Reflection;
4+
5+
namespace SfDataGridSample
6+
{
7+
public partial class MainPage : ContentPage
8+
{
9+
public MainPage()
10+
{
11+
InitializeComponent();
12+
}
13+
14+
private void sfGrid_QueryRowHeight(object sender, Syncfusion.Maui.DataGrid.DataGridQueryRowHeightEventArgs e)
15+
{
16+
if (e.RowIndex > 0)
17+
{
18+
e.Height = e.GetIntrinsicRowHeight(e.RowIndex);
19+
e.Handled = true;
20+
(sender as SfDataGrid).InvalidateRowHeight(e.RowIndex, true);
21+
}
22+
}
23+
}
24+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.Extensions.Logging;
2+
using Syncfusion.Maui.Core.Hosting;
3+
4+
namespace SfDataGridSample
5+
{
6+
public static class MauiProgram
7+
{
8+
public static MauiApp CreateMauiApp()
9+
{
10+
var builder = MauiApp.CreateBuilder();
11+
builder
12+
.UseMauiApp<App>()
13+
.ConfigureSyncfusionCore()
14+
.ConfigureFonts(fonts =>
15+
{
16+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
17+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
18+
});
19+
20+
#if DEBUG
21+
builder.Logging.AddDebug();
22+
#endif
23+
24+
return builder.Build();
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)