When overridden in a derived class, gets the height to be used in for automatically resizing columns.
[Visual Basic] MustOverride Public Function GetPreferredHeight( _ ByVal g As Graphics, _ ByVal value As Object _ ) As Integer [C#] public abstract int GetPreferredHeight( Graphics g, object value ); [C++] public: virtual int GetPreferredHeight( Graphics* g, Object* value ) = 0; [JScript] public abstract function GetPreferredHeight( g : Graphics, value : Object ) : int;
The height used for auto resizing a cell.
The GetPreferredSize will usually be invoked from a mouse down event to resize a column's height for a long string.
The following example shows a possible override of the GetPreferredSize method.
[Visual Basic]
Overrides Function GetAutoResizeHeight(ByVal g As UI.System.Drawing.Graphics, ByVal value As object) As Long ' Use the MeasureString function to return a SizeF. The function uses ' values (Width and xMargin) that have been calculated and stored elsewhere. Dim myF As System.Drawing.SizeF myF = MeasureString(value, Me.Font, Width - 2*XMargin) GetAutoResizeHeight = myF.Height End Function
DataGridColumn Class | DataGridColumn Members | System.WinForms Namespace | GetPreferredSize | GetMinimumHeight