Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,60 @@
# How-to-refresh-the-row-height-programmatically-in-.NET-MAUI-DataGrid--SfDataGrid-
This demo shows how to refresh the row height programmatically in .NET MAUI DataGrid (SfDataGrid) ?
# How to refresh the row height programmatically in .NET MAUI DataGrid (SfDataGrid) ?
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).

## xaml
```
<ContentPage.BindingContext>
<local:EmployeeViewModel x:Name="viewModel" />
</ContentPage.BindingContext>

<syncfusion:SfDataGrid x:Name="sfGrid"
GridLinesVisibility="Both"
HeaderGridLinesVisibility="Both"
AutoGenerateColumnsMode="None"
QueryRowHeight="sfGrid_QueryRowHeight"
ItemsSource="{Binding Employees}">

<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridNumericColumn MappingName="EmployeeID"
Format="#"
HeaderText="Employee ID" />
<syncfusion:DataGridTextColumn MappingName="Name"
HeaderText="Employee Name" />
<syncfusion:DataGridTextColumn MappingName="Title"
HeaderText="Designation" />
<syncfusion:DataGridDateColumn MappingName="HireDate"
HeaderText="Hire Date" />

</syncfusion:SfDataGrid.Columns>

</syncfusion:SfDataGrid>
```

## Xaml.cs
The code below demonstrates how to refresh the row height programmatically in the QueryRowHeight event of SfDataGrid.
```
private void sfGrid_QueryRowHeight(object sender, Syncfusion.Maui.DataGrid.DataGridQueryRowHeightEventArgs e)
{
if (e.RowIndex > 0)
{
e.Height = e.GetIntrinsicRowHeight(e.RowIndex);
e.Handled = true;
(sender as SfDataGrid).InvalidateRowHeight(e.RowIndex, true);
}
}
```

<img src="https://support.syncfusion.com/kb/agent/attachment/inline?token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjM1ODMxIiwib3JnaWQiOiIzIiwiaXNzIjoic3VwcG9ydC5zeW5jZnVzaW9uLmNvbSJ9.xZVPkjhEEs9zD1jeqE_bzi53n_rgQmeN5v6okG8A1Mg" width=700/>

[View sample in GitHub](https://github.com/SyncfusionExamples/How-to-refresh-the-row-height-programmatically-in-.NET-MAUI-DataGrid--SfDataGrid-)

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).

##### Conclusion

I hope you enjoyed learning about how to refresh the row height programmatically in the .NET MAUI DataGrid (SfDataGrid).

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.
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.

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!
22 changes: 22 additions & 0 deletions SfDataGridSample/SfDataGridSample.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35506.116 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SfDataGridSample", "SfDataGridSample\SfDataGridSample.csproj", "{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEB0310E-49AF-4663-87C2-E585EEFE9E5E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
14 changes: 14 additions & 0 deletions SfDataGridSample/SfDataGridSample/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:SfDataGridSample"
x:Class="SfDataGridSample.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
15 changes: 15 additions & 0 deletions SfDataGridSample/SfDataGridSample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace SfDataGridSample
{
public partial class App : Application
{
public App()
{
InitializeComponent();
}

protected override Window CreateWindow(IActivationState? activationState)
{
return new Window(new AppShell());
}
}
}
15 changes: 15 additions & 0 deletions SfDataGridSample/SfDataGridSample/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="SfDataGridSample.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:SfDataGridSample"
Shell.FlyoutBehavior="Flyout"
Title="SfDataGridSample">

<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

</Shell>
10 changes: 10 additions & 0 deletions SfDataGridSample/SfDataGridSample/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SfDataGridSample
{
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
27 changes: 27 additions & 0 deletions SfDataGridSample/SfDataGridSample/ColorConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Syncfusion.Maui.DataGrid;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SfDataGridSample
{
public class ColorConverter : IValueConverter
{
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo info)
{
var dataGridRow = value as DataGridRow;
var rowData = dataGridRow.DataRow.RowData;
if ((rowData as Employee).EmployeeID == 1005)
return Colors.LightBlue;
else
return Colors.White;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
34 changes: 34 additions & 0 deletions SfDataGridSample/SfDataGridSample/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid"
xmlns:local="clr-namespace:SfDataGridSample"
x:Class="SfDataGridSample.MainPage">

<ContentPage.BindingContext>
<local:EmployeeViewModel x:Name="viewModel" />
</ContentPage.BindingContext>

<syncfusion:SfDataGrid x:Name="sfGrid"
GridLinesVisibility="Both"
HeaderGridLinesVisibility="Both"
AutoGenerateColumnsMode="None"
QueryRowHeight="sfGrid_QueryRowHeight"
ItemsSource="{Binding Employees}">

<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridNumericColumn MappingName="EmployeeID"
Format="#"
HeaderText="Employee ID" />
<syncfusion:DataGridTextColumn MappingName="Name"
HeaderText="Employee Name" />
<syncfusion:DataGridTextColumn MappingName="Title"
HeaderText="Designation" />
<syncfusion:DataGridDateColumn MappingName="HireDate"
HeaderText="Hire Date" />

</syncfusion:SfDataGrid.Columns>

</syncfusion:SfDataGrid>

</ContentPage>
24 changes: 24 additions & 0 deletions SfDataGridSample/SfDataGridSample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Syncfusion.Maui.DataGrid;
using Syncfusion.Maui.DataGrid.Helper;
using System.Reflection;

namespace SfDataGridSample
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}

private void sfGrid_QueryRowHeight(object sender, Syncfusion.Maui.DataGrid.DataGridQueryRowHeightEventArgs e)
{
if (e.RowIndex > 0)
{
e.Height = e.GetIntrinsicRowHeight(e.RowIndex);
e.Handled = true;
(sender as SfDataGrid).InvalidateRowHeight(e.RowIndex, true);
}
}
}
}
27 changes: 27 additions & 0 deletions SfDataGridSample/SfDataGridSample/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;
using Syncfusion.Maui.Core.Hosting;

namespace SfDataGridSample
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureSyncfusionCore()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}
}
Loading