Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
15
Bug Report: UltraGrid PerformAutoResizeColumns() doesn't honor column MaxWidth when Column is DropDownList and MinWidth=MaxWidth
posted

Details

There is a bug in the UltraGrid that caused a Column's MaxWidth to be ignored. There are problem multiple ways to encounter it, but this is the one I have identified. We are on 2015 Vol 2, but I downloaded a trial of the latest version 2018 Vol 2. I verifed that this bug still exists.


Bug Report

When a Column is DropDownList (i.e. an ValueList) and it's MaxWidth=MinWidth, the MaxWidth value is ignored.

For example, this will cause the column to be 58px. However, if you manually resize the columns (with the mouse), it quickly snaps to the specified MaxWidth.

    this.ultraGrid1.DisplayLayout.Bands[0].Columns["Enum"].ValueList = valueList;
    this.ultraGrid1.DisplayLayout.Bands[0].Columns["Enum"].MaxWidth = 20;
    this.ultraGrid1.DisplayLayout.Bands[0].Columns["Enum"].MinWidth = 20;
    this.ultraGrid1.DisplayLayout.PerformAutoResizeColumns(false, PerformAutoSizeType.AllRowsInBand, AutoResizeColumnWidthOptions.All);

This can be worked around by making the MaxWidth 1 px larger than the MinWidth.

    this.ultraGrid1.DisplayLayout.Bands[0].Columns["Enum"].ValueList = valueList;
    this.ultraGrid1.DisplayLayout.Bands[0].Columns["Enum"].MaxWidth = 21;
    this.ultraGrid1.DisplayLayout.Bands[0].Columns["Enum"].MinWidth = 20;
    this.ultraGrid1.DisplayLayout.PerformAutoResizeColumns(false, PerformAutoSizeType.AllRowsInBand, AutoResizeColumnWidthOptions.All);


Solution

I believe I've identified the fix. In UltraGridColumn there is an internal method named SetWidth(). It enforces the MinWidth and MaxWidth, but there is a exclusive test that should be inclusive.

The last version we have a license for is 'Infragistics 2015 Vol 2. 2118'. This is line #11129 in 'CLR4.0\UltraWinGrid\Columns.cs"

    if ( maxWidth > minWidth  )
        newWidth = System.Math.Min( newWidth, maxWidth );

Changing that to a greater than or equal, fixes the bug.

    if ( maxWidth >= minWidth  )
        newWidth = System.Math.Min( newWidth, maxWidth );

I attached an example.1882.UltraGridBug.zip