GridLayout
A layout panel that arranges child elements in a sophisticated grid structure with configurable rows, columns, spanning, and advanced sizing modes.
GridLayout provides comprehensive grid-based layout capabilities that rival modern CSS Grid and HTML table functionality. It supports column and row definitions with multiple sizing modes including proportional sizing, fixed pixel dimensions, auto-sizing based on content, and star-sizing for flexible space distribution.
Advanced features include:
- Row and column spanning for elements that need to occupy multiple grid cells
- Individual cell padding control for precise element positioning within cells
- Proportional sizing with star notation for responsive column and row widths
- Auto-sizing columns and rows based on their content requirements
- Stretch modes for filling available horizontal and vertical space
- DPI-aware scaling for consistent appearance across different display densities
GridLayout is extensively used for creating complex, table-like layouts such as forms, data entry screens, dashboard layouts, property grids, and any UI where precise row and column control with responsive behavior is required. The layout system automatically handles cell positioning, sizing calculations, and element arrangement based on the defined grid structure and content requirements.
Definition
Namespace:Telerik.WinControls.Layouts
Assembly:Telerik.WinControls.dll
Syntax:
public class GridLayout : LayoutPanel, IDisposable, INotifyPropertyChanged, ICustomTypeDescriptor, ISupportSystemSkin, IStylableNode
Inheritance: objectDisposableObjectRadObjectRadElementLayoutPanelGridLayout...
Implements:
Inherited Members
Constructors
Initializes a new instance of the GridLayout class with a single cell (1x1 grid).
Initializes a new instance of the GridLayout class with the specified number of columns and rows.
public GridLayout(int columnsCount, int rowsCount)
The number of columns to create in the grid. Must be greater than 0.
rowsCountintThe number of rows to create in the grid. Must be greater than 0.
This constructor creates a grid layout with the specified dimensions. Each row and column initially uses Proportional sizing; configure its sizing mode and related dimensions through the Rows and Columns collections.
This is the most efficient way to create a grid when you know the required dimensions in advance, as it pre-allocates the internal collections and avoids dynamic resizing during layout operations.
Fields
Identifies the attached property that adds padding inside a child's grid cell, reducing its available measurement and arrangement area.
public static readonly RadProperty CellPaddingProperty
Identifies the attached property that sets how many consecutive columns a child occupies; the default is 1.
public static readonly RadProperty ColSpanProperty
Identifies the attached property that selects a child's zero-based column in Columns.
public static readonly RadProperty ColumnIndexProperty
Identifies the attached property that selects a child's zero-based row in Rows.
public static readonly RadProperty RowIndexProperty
Identifies the attached property that sets how many consecutive rows a child occupies; the default is 1.
public static readonly RadProperty RowSpanProperty
Properties
Columns
List<GridLayoutColumn>
Gets or sets the collection of column definitions that determine the width and sizing behavior of grid columns.
public List<GridLayoutColumn> Columns { get; set; }
A List<T> of GridLayoutColumn objects that define the grid's column structure.
Each GridLayoutColumn in this collection represents a column in the grid and provides configuration for width sizing behavior including:
- Fixed pixel widths for precise column sizing
- Proportional star-sizing for flexible width distribution
- Auto-sizing based on column content requirements
Modifying this collection triggers layout invalidation and re-measurement to accommodate the new column structure. The column index of child elements should correspond to valid indices within this collection.
Rows
List<GridLayoutRow>
Gets or sets the collection of row definitions that determine the height and sizing behavior of grid rows.
public List<GridLayoutRow> Rows { get; set; }
A List<T> of GridLayoutRow objects that define the grid's row structure.
Each GridLayoutRow in this collection represents a row in the grid and provides configuration for height sizing behavior including:
- Fixed pixel heights for precise row sizing
- Proportional star-sizing for flexible height distribution
- Auto-sizing based on row content requirements
Modifying this collection triggers layout invalidation and re-measurement to accommodate the new row structure. The row index of child elements should correspond to valid indices within this collection.
Methods
Handles DPI scaling changes by invalidating layout measurements and updating the grid structure.
public override void DpiScaleChanged(SizeF scaleFactor)
The scaling factor applied due to DPI changes.
Overrides:
This method ensures that the grid layout responds appropriately to DPI changes by:
- Invalidating existing measurements to force recalculation with new DPI
- Triggering a complete layout update to apply DPI-scaled dimensions
- Ensuring fixed-size columns and rows are properly scaled
This maintains visual consistency and proper proportions when the application is moved between displays with different DPI settings or when system DPI scaling changes.
Calculates row and column sizes, then measures each child within its spanned cell area.
protected override SizeF MeasureOverride(SizeF availableSize)
The size available for measurement.
Returns:The desired size computed from the row and column dimensions and child measurements.
Overrides:
Panel padding and border thickness are subtracted from the available size before row and column sizing.