menu

WinForms

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class AutoSizeController - WindowsForms API Reference | Syncfusion

    Show / Hide Table of Contents

    Class AutoSizeController

    Represents a class that provides the implementation to calculate column widths based on the AutoSizeColumnsMode.

    Inheritance
    System.Object
    AutoSizeController
    Implements
    System.IDisposable
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Syncfusion.WinForms.DataGrid
    Assembly: Syncfusion.SfDataGrid.WinForms.dll
    Syntax
    public class AutoSizeController : IDisposable

    Constructors

    AutoSizeController(SfDataGrid)

    Initializes a new instance of the AutoSizeController class.

    Declaration
    public AutoSizeController(SfDataGrid dataGrid)
    Parameters
    Type Name Description
    SfDataGrid dataGrid

    The SfDataGrid.

    Properties

    AutoSizeCalculationMode

    Gets or sets a value indicating the mode for calculating the width of the cell based on cell content.

    Declaration
    public AutoSizeCalculationMode AutoSizeCalculationMode { get; set; }
    Property Value
    Type
    AutoSizeCalculationMode

    AutoSizeRange

    Gets or sets a value indicating whether to auto sizing columns based on VisibleRows only or Table.

    Declaration
    public AutoSizeRange AutoSizeRange { get; set; }
    Property Value
    Type
    AutoSizeRange

    DataGrid

    Gets the reference to the SfDataGrid control.

    Declaration
    public SfDataGrid DataGrid { get; }
    Property Value
    Type
    SfDataGrid

    Methods

    CalculateAllCellsExceptHeaderWidth(GridColumn, Boolean)

    Calculates the width for the column based on cell value when column sizer is or .

    Declaration
    protected virtual double CalculateAllCellsExceptHeaderWidth(GridColumn column, bool setWidth = true)
    Parameters
    Type Name Description
    GridColumn column

    The corresponding column to calculate the cell width.

    System.Boolean setWidth

    Indicates whether calculated cell width is set as an actual width of the column.

    Returns
    Type Description
    System.Double

    Returns the corresponding width for the specified column.

    CalculateAllCellsWidth(GridColumn, Boolean)

    Calculates the width for the column to fit the content when column sizer is .

    Declaration
    protected virtual double CalculateAllCellsWidth(GridColumn column, bool isAllCells = false)
    Parameters
    Type Name Description
    GridColumn column

    The corresponding column to calculate the width based on .

    System.Boolean isAllCells

    Indicates whether the column sizer type is AllCells.

    Returns
    Type Description
    System.Double

    Returns the column width based on .

    Remarks

    Override this method and customize the calculation of .

    CalculateColumnHeaderWidth(GridColumn, Boolean)

    Calculates the width of the column based on header text when or is set.

    Declaration
    protected virtual int CalculateColumnHeaderWidth(GridColumn column, bool setWidth = true)
    Parameters
    Type Name Description
    GridColumn column

    The corresponding column to calculate its header width.

    System.Boolean setWidth

    Indicates whether calculated header width is set as an actual width of the column.

    Returns
    Type Description
    System.Int32

    Returns the width of the specified column.

    Dispose()

    Releases the resources used by this class.

    Declaration
    public void Dispose()

    Dispose(Boolean)

    Releases the resources used by this class.

    Declaration
    protected virtual void Dispose(bool disposing)
    Parameters
    Type Name Description
    System.Boolean disposing

    true to release both managed and unmanaged resources; false to release only unmanaged resources.

    GetAllCellsWidth(GridColumn)

    Gets the width for the specified column when the column sizer is or .

    Declaration
    protected virtual double GetAllCellsWidth(GridColumn column)
    Parameters
    Type Name Description
    GridColumn column

    The corresponding column to get the auto width.

    Returns
    Type Description
    System.Double

    Returns the auto width for the specified column.

    Exceptions
    Type Condition
    System.InvalidOperationException

    Thrown when the column is null.

    GetAutoRowHeight(Int32, RowAutoFitOptions, out Int32)

    Gets the auto fit row height for the given row index.

    Declaration
    public bool GetAutoRowHeight(int rowIndex, RowAutoFitOptions options, out int rowHeight)
    Parameters
    Type Name Description
    System.Int32 rowIndex

    The row index that needs to calculates the height.

    RowAutoFitOptions options

    The options for calculating the row height.

    System.Int32 rowHeight

    The row height for the given row index.

    Returns
    Type Description
    System.Boolean

    Returns true, if the row height is calculated; otherwise return false.

    Remarks

    It will return the row height only for the header and record rows.

    GetCellHeight(Size, GridColumn, Object)

    Gets the size of the cell to calculate the width of the specified column when AutoSizeColumnsMode is or .

    Declaration
    protected virtual Size GetCellHeight(Size clientSize, GridColumn column, object data)
    Parameters
    Type Name Description
    System.Drawing.Size clientSize

    The client size of the cell.

    GridColumn column

    The corresponding column to measure its cell size.

    System.Object data

    The corresponding data to measure the text size in cell.

    Returns
    Type Description
    System.Drawing.Size

    Returns the size of the cell.

    GetCellSize(GridColumn, Object)

    Gets the size of the cell to calculate the width of the specified column when AutoSizeColumnsMode is or .

    Declaration
    protected virtual Size GetCellSize(GridColumn column, object data)
    Parameters
    Type Name Description
    GridColumn column

    The corresponding column to measure its cell size.

    System.Object data

    The corresponding data to measure the text size in cell.

    Returns
    Type Description
    System.Drawing.Size

    Returns the size of the cell.

    GetColumnAutoSizeWidth(GridColumn)

    Calculate width for cells contents for the given column.

    Declaration
    protected virtual int GetColumnAutoSizeWidth(GridColumn column)
    Parameters
    Type Name Description
    GridColumn column

    The GridColumn.

    Returns
    Type Description
    System.Int32

    Returns the calculated width based on cell contents.

    GetColumnToFill()

    Gets the column to fill the remaining view port size based on or column sizer.

    Declaration
    protected virtual GridColumn GetColumnToFill()
    Returns
    Type Description
    GridColumn

    The column to fill.

    GetDisplayText(GridColumn, Object)

    Gets the display text of cell for the specified column and record.

    Declaration
    protected virtual string GetDisplayText(GridColumn column, object record)
    Parameters
    Type Name Description
    GridColumn column

    The corresponding column to get the display text of cell.

    System.Object record

    The corresponding record to get the display text.

    Returns
    Type Description
    System.String

    Returns the display text of the corresponding column.

    GetHeaderCellWidth(GridColumn)

    Calculate width for header based on given column.

    Declaration
    protected virtual int GetHeaderCellWidth(GridColumn column)
    Parameters
    Type Name Description
    GridColumn column

    The GridColumn.

    Returns
    Type Description
    System.Int32

    Returns the calculated header width.

    MeasureHeaderText(String, GridColumn)

    Measures the header text of the specified column when the column sizing is or .

    Declaration
    protected virtual Size MeasureHeaderText(string displayText, GridColumn column)
    Parameters
    Type Name Description
    System.String displayText

    The displayText to measure.

    GridColumn column

    The corresponding column to measure the text.

    Returns
    Type Description
    System.Drawing.Size

    Returns the calculated size of the header text.

    MeasureText(String, GridColumn)

    Measures the text of the specified column when the column sizing is or .

    Declaration
    protected virtual Size MeasureText(string displayText, GridColumn column)
    Parameters
    Type Name Description
    System.String displayText

    The displayText to measure.

    GridColumn column

    The corresponding column to measure the text.

    Returns
    Type Description
    System.Drawing.Size

    Returns the calculated size of the text.

    Refresh()

    Refreshes column widths when the AutoSizeColumnsMode property value changes at SfDataGrid or GridColumn level.

    Declaration
    public void Refresh()

    ResetAutoSizeWidth(GridColumn)

    Resets the auto calculated width for the specified column.

    Declaration
    public void ResetAutoSizeWidth(GridColumn column)
    Parameters
    Type Name Description
    GridColumn column

    The corresponding column to reset the auto width.

    Remarks

    The auto calculated column width is reset to 0 ,if the column sizing is need to recalculate based on the data.

    Exceptions
    Type Condition
    System.InvalidOperationException

    Thrown when the column is null.

    ResetAutoSizeWidth(String)

    Resets the auto calculated width for the specified column.

    Declaration
    public void ResetAutoSizeWidth(string mappingName)
    Parameters
    Type Name Description
    System.String mappingName

    The mapping name of the corresponding column to reset the auto width.

    Remarks

    The auto calculated column width is reset to 0 ,if the column sizing is need to recalculate based on the data.

    Exceptions
    Type Condition
    System.InvalidOperationException

    Thrown when the mapping name is null or when column does not matches the mapping name.

    ResetAutoSizeWidthForAllColumns()

    Resets the auto calculated width of all the columns.

    Declaration
    public void ResetAutoSizeWidthForAllColumns()

    SetAllCellsWidth(GridColumn, Double)

    Sets the width for the specified column based on column sizer.

    Declaration
    protected virtual void SetAllCellsWidth(GridColumn column, double width)
    Parameters
    Type Name Description
    GridColumn column

    The corresponding column to set AllCells width.

    System.Double width

    The corresponding width set as AllCells width.

    Exceptions
    Type Condition
    System.InvalidOperationException

    Thrown when the column is null.

    SetColumnWidth(GridColumn, Double)

    Sets the width for the specified column based on MinimumWidth and MaximumWidth property value changes.

    Declaration
    public double SetColumnWidth(GridColumn column, double columnWidth)
    Parameters
    Type Name Description
    GridColumn column

    The corresponding column to set the width.

    System.Double columnWidth

    The corresponding width to set.

    Returns
    Type Description
    System.Double

    Returns the corresponding width for the specified column.

    SetFillWidth(Double, IEnumerable<GridColumn>)

    Sets the column width based on mode.

    Declaration
    protected virtual void SetFillWidth(double remainingColumnWidth, IEnumerable<GridColumn> remainingColumns)
    Parameters
    Type Name Description
    System.Double remainingColumnWidth

    The available width to adjust the column based on Star column sizer.

    System.Collections.Generic.IEnumerable<GridColumn> remainingColumns

    The collection columns that need to be set star width.

    Remarks

    Override this method to customize the width calculation in SfDataGrid.

    SetNoneWidth(GridColumn, Int32)

    Sets the width for the specified column based on column sizer.

    Declaration
    protected virtual double SetNoneWidth(GridColumn column, int width)
    Parameters
    Type Name Description
    GridColumn column

    The corresponding column to set None width.

    System.Int32 width

    The width to set as None width.

    Returns
    Type Description
    System.Double

    Returns the None width for the specified column.

    Implements

    System.IDisposable
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved