From 85f0d133782a058bc77aea385c61f89d19fd963e Mon Sep 17 00:00:00 2001 From: Sreemon Premkumar M Date: Fri, 22 Aug 2025 10:04:15 +0530 Subject: [PATCH 1/2] ES-975464 - Resolve the ReadMe file length issue in this sample repository --- README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e413fbc..22967d9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,19 @@ -# fit-the-columns-and-rows-size-based-on-custom-control-size +# Fit the columns and rows size based on custom control size + This example demonstrates how to adjust the column and row height based on custom control size + +When [WPF GridControl](https://help.syncfusion.com/wpf/gridcontrol/overview) is placed inside custom control and if you want to auto fit the row/column size of `GridControl` based on custom control resized position, then you can invoke [SizeChanged](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.control.sizechanged?view=netframework-4.8) event of `GridControl` and set the [RowHeights](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridModel.html#Syncfusion_Windows_Controls_Grid_GridModel_RowHeights) and [ColumnWidths](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridModel.html#Syncfusion_Windows_Controls_Grid_GridModel_ColumnWidths) property of [GridModel](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridModel.html) to the resized height/width. + +``` csharp +grid.SizeChanged += grid_SizeChanged; +//To autofit the cells based on custom control resizing, +void grid_SizeChanged(object sender, SizeChangedEventArgs e) +{ + double width = (e.NewSize.Width - grid.Model.ColumnWidths.DefaultLineSize - 1) / (grid.Model.ColumnCount - 1); + double height = (e.NewSize.Height - grid.Model.RowHeights.DefaultLineSize - 1) / (grid.Model.RowCount - 1); + for (int i = 1; i < grid.Model.ColumnCount; ++i) + grid.Model.ColumnWidths[i] = width; + for (int j = 1; j < grid.Model.RowCount; ++j) + grid.Model.RowHeights[j] = height; +} +``` \ No newline at end of file From 321d11ea8891fe4ebc637de1e3000288295b43a4 Mon Sep 17 00:00:00 2001 From: SreemonPremkumarM Date: Fri, 21 Nov 2025 00:11:43 +0530 Subject: [PATCH 2/2] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 22967d9..e76bd4a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Fit the columns and rows size based on custom control size +# Fit the Columns and Rows Size Based on Custom Control Size This example demonstrates how to adjust the column and row height based on custom control size @@ -16,4 +16,4 @@ void grid_SizeChanged(object sender, SizeChangedEventArgs e) for (int j = 1; j < grid.Model.RowCount; ++j) grid.Model.RowHeights[j] = height; } -``` \ No newline at end of file +```