Nevron Open Vision Documentation
Grid / Columns / Column- Width
In This Topic
    Column- Width
    In This Topic
     About Column Width

    There are several ways in which the width of the column can determined, which is controlled by the NColumn.WidthMode property, that accepts values from the ENColumnWidthMode enumeration:

    • Auto - The size is based on the contents of both the cells and the column header (the default)
    • Fixed - The size is a fixed value defined by the FixedWidth property.
    • SizeToCells - The size is based on the contents of the cells.
    • SizeToHeader - The size is based on the contents of the column header.
    • Percent - The size is a percent proportion of available space.

    By default the column WidthMode is set to Auto. Additionally the user can perform the so called "Best Fit" operation, by double clicking on the space between two columns. The rest of this topic discusses the different width modes and the "Best Fit" operation in details.

     Fixed Column Width

    To fix the width of a certain column to a user specified value, you need to set the WidthMode property to Fixed and the FixedWidth property to the width that you desire for the column:

    Fixed Column Width
    Copy Code
    column.WidthMode = ENColumnWidthMode.Fixed;
    column.FixedWidth = 100;
    
     Automatic Column Width

    When it comes to automatic column width, you have three WidthMode options to choose from - size the column to the header (SizeToHeader), size the column to the cells (SizeToCells) and size the column to both the cells and the header (Auto - the default). The following code example sizes the column to the header:

    Size column to header
    Copy Code
    column.WidthMode = ENColumnWidthMode.SizeToHeader;
    

    It is important to note that when the size of the cells is taken into account, the grid measures only the cells that have been displayed (realized). Cells which have not been displayed are not taken into account. That is why the size of certain columns may auto grow while you scroll the grid.

     Percentage Column Width

    The size of columns can be expressed as a percentage of the available width by setting the WidthMode to Percent. The available width from which the percentage calculation takes place is the width of the grid, minus the size of all fixed and automatically resized columns. The following example creates three columns, the last one of which occupies the remaining width:

    Percentage Column width
    Copy Code
    // make a fixed column with size 150 dips
    column1.WidthMode = ENColumnWidthMode.Fixed;
    column1.FixedWidth = 150;
    // make a percentage column, that occupies the entire available width
    column2.WidthMode = ENColumnWidthMode.Percent;
    column2.WidthPercent = 100;
    
     Column Best Fit

    The column "Best Fit" operation can be performed by the user when he double-clicks on the separator between columns. This operation calculates a column size that is large enough to incorporate the header and all displayed cells and sets this size as fixed column width. The "Best Fit" operation can also be performed via code like this:

    Best Fit Example
    Copy Code
    column.BestFit();