Skip to content

SyncfusionExamples/wpf-gridcontrol-fit-the-columns-and-rows-size-based-on-content

Repository files navigation

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 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 event of GridControl and set the RowHeights and ColumnWidths property of GridModel to the resized height/width.

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;
}

About

This example demonstrates how to adjust the column and row height based on custom control size

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 6

Languages