Skip to content

Commit 85f0d13

Browse files
ES-975464 - Resolve the ReadMe file length issue in this sample repository
1 parent 1a0e782 commit 85f0d13

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
# fit-the-columns-and-rows-size-based-on-custom-control-size
1+
# Fit the columns and rows size based on custom control size
2+
23
This example demonstrates how to adjust the column and row height based on custom control size
4+
5+
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.
6+
7+
``` csharp
8+
grid.SizeChanged += grid_SizeChanged;
9+
//To autofit the cells based on custom control resizing,
10+
void grid_SizeChanged(object sender, SizeChangedEventArgs e)
11+
{
12+
double width = (e.NewSize.Width - grid.Model.ColumnWidths.DefaultLineSize - 1) / (grid.Model.ColumnCount - 1);
13+
double height = (e.NewSize.Height - grid.Model.RowHeights.DefaultLineSize - 1) / (grid.Model.RowCount - 1);
14+
for (int i = 1; i < grid.Model.ColumnCount; ++i)
15+
grid.Model.ColumnWidths[i] = width;
16+
for (int j = 1; j < grid.Model.RowCount; ++j)
17+
grid.Model.RowHeights[j] = height;
18+
}
19+
```

0 commit comments

Comments
 (0)