DataGridViewCell.GetPreferredSize Method (Graphics, DataGridViewCellStyle, Int32, Size)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Calculates the preferred size, in pixels, of the cell.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

protected virtual Size GetPreferredSize(
	Graphics graphics,
	DataGridViewCellStyle cellStyle,
	int rowIndex,
	Size constraintSize


Type: System.Drawing.Graphics

The Graphics used to draw the cell.

Type: System.Windows.Forms.DataGridViewCellStyle

A DataGridViewCellStyle that represents the style of the cell.

Type: System.Int32

The zero-based row index of the cell.

Type: System.Drawing.Size

The cell's maximum allowable size.

Return Value

Type: System.Drawing.Size

A Size that represents the preferred size, in pixels, of the cell.

The GetPreferredSize method in the base class DataGridViewCell always returns a Size with a width and height of -1. However, this method is overridden in the derived cell classes to return proper values.

.NET Framework
Available since 2.0
Return to top