Skip to content

Commit 15a0e0c

Browse files
authored
Merge pull request #2 from SyncfusionExamples/ES-975464
ES-975464 - Resolve the ReadMe file length issue in this sample repository
2 parents c46a00b + 384fc80 commit 15a0e0c

File tree

2 files changed

+53
-2811
lines changed

2 files changed

+53
-2811
lines changed

README.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,53 @@
1-
# fit-the-column-width-and-row-height-based-on-content-size
2-
This example demonstrates how to adjust the columns and rows based on content size
1+
# Fit the Column Width and Row Height Based on Content Size
2+
3+
This example demonstrates how to adjust the columns and rows based on content size in [WPF GridControl](https://help.syncfusion.com/wpf/gridcontrol/overview).
4+
5+
### Autofit row height
6+
7+
`GridControl` provides the support to auto fit the row height based on content of the cells using [ResizeRowsToFit](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridModel.html#Syncfusion_Windows_Controls_Grid_GridModel_ResizeRowsToFit_Syncfusion_Windows_Controls_Grid_GridRangeInfo_Syncfusion_Windows_Controls_Grid_GridResizeToFitOptions_) method which accepts the following parameters,
8+
9+
* [GridRangeInfo](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridRangeInfo.html) - Specifies the range where `GridControl` auto fits the rows based on the cell content.
10+
* [GridResizeToFitOptions](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridResizeToFitOptions.html) - Specifies the auto fit settings to customize the auto fit behavior.
11+
12+
``` csharp
13+
//To auto fit single row 2,
14+
grid.Model.ResizeRowsToFit(GridRangeInfo.Row(2), GridResizeToFitOptions.NoShrinkSize);
15+
16+
//To auto fit range of rows from 3 to 6,
17+
grid.Model.ResizeRowsToFit(GridRangeInfo.Rows(3,6), GridResizeToFitOptions.NoShrinkSize);
18+
19+
//To auto fit range of cell's(including Covered cells) row height,
20+
this.grid.Model.ResizeRowsToFit(GridRangeInfo.Cells(1, 1, 2, 2),GridResizeToFitOptions.IncludeCellsWithinCoveredRange);
21+
22+
//To auto fit entire grid's row height,
23+
this.grid.Model.ResizeRowsToFit(GridRangeInfo.Table(), GridResizeToFitOptions.None);
24+
```
25+
### Autofit column width
26+
27+
`GridControl` provides the support to auto fit the column width based on content of the cells using [ResizeColumnsToFit](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridModel.html#Syncfusion_Windows_Controls_Grid_GridModel_ResizeColumnsToFit_Syncfusion_Windows_Controls_Grid_GridRangeInfo_Syncfusion_Windows_Controls_Grid_GridResizeToFitOptions_) method which accepts the following parameters,
28+
29+
* [GridRangeInfo](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridRangeInfo.html) - Specifies the range where GridControl auto fits the columns based on the cell content.
30+
* [GridResizeToFitOptions](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridResizeToFitOptions.html) - Specifies the auto fit settings to customize the auto fit behavior.
31+
32+
``` csharp
33+
//To auto fit single column 2,
34+
grid.Model.ResizeColumnsToFit(GridRangeInfo.Col(2), GridResizeToFitOptions.NoShrinkSize);
35+
36+
//To auto fit range of Columns from 3 to 6,
37+
grid.Model.ResizeColumnsToFit(GridRangeInfo.Cols(3,6), GridResizeToFitOptions.NoShrinkSize);
38+
39+
//To auto fit range of cell's(including Covered cells) column width,
40+
this.grid.Model.ResizeColumnsToFit(GridRangeInfo.Cells(1, 1, 2, 2),GridResizeToFitOptions.IncludeCellsWithinCoveredRange);
41+
42+
//To auto fit entire grid's column width,
43+
this.grid.Model.ResizeColumnsToFit(GridRangeInfo.Table(), GridResizeToFitOptions.None);
44+
```
45+
46+
### Autofit Cells based on Wrap Text
47+
48+
To autofit the cell's height based on the applied wrap text, need to use [ResizeRowsToFit](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridModel.html#Syncfusion_Windows_Controls_Grid_GridModel_ResizeRowsToFit_Syncfusion_Windows_Controls_Grid_GridRangeInfo_Syncfusion_Windows_Controls_Grid_GridResizeToFitOptions_) method.
49+
50+
``` csharp
51+
this.grid.Model[2, 2].TextWrapping = TextWrapping.Wrap;
52+
this.grid.Model.ResizeRowsToFit(GridRangeInfo.Cell(2, 2),GridResizeToFitOptions.NoShrinkSize);
53+
```

0 commit comments

Comments
 (0)