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
column PerformAutoResize and setting our own max width?
posted

We are using the col.PerformAutoResize(AutoResizeType, IncludeHeadersInAutoResize()) in combination with our own internal column formats that may restrict a columns max width. So we call PerformAutoResize (I've also just tried CalculateAutoResizeWidth) and if the calculated size is greater than the max width that we want, we set the column width 

 ug_.BeginUpdate();

foreach (UltraGridColumn ucol in band.Columns)
{
	ucol.PerformAutoResize(AutoResizeType, IncludeHeadersInAutoResize());

	ColumnView2 cv = ucol.Tag as ColumnView2;
	if (cv != null && cv.ColFormatDef != null && cv.ColFormatDef.MaxWidth >= 0)
	{
		if (ucol.Width > cv.ColFormatDef.MaxWidth)
		{
			ucol.MaxWidth = cv.ColFormatDef.MaxWidth;
		}
	}
}
 ug_.EndUpdate();

I've also tried it just calcing the value of the autoresize

int widthToUse = ucol.CalculateAutoResizeWidth(PerformAutoSizeType.AllRowsInBand, IncludeHeadersInAutoResize());

and setting the width of the column if the calced width is greater than the cv.ColFormatDef.MaxWidth.

Anyway, what happens is that when the grid is drawn, the max width that we set instead of the calced width is not enforced. But the interesting thing is that if I look in the grid at the actual width that the column is, it'll tell me it's my max width that i put in. For example, if I set the max width of a column to 40 instead of the calced auto size, but the column header is > 40 and the calced auto size is greater than 40, I see my code setting the column width to 40, but the grid does not draw the column at a width of 40. If I inspect the values of the grid, I see that this column's width is set to 40. It just isn't being drawn that way (it's actually being drawn at the width of the header). If I loop through my code 1 more time, it does not change. But if I loop through it one MORE time, it finally sets the column width to 40.

So I'm setting the width of some columns less than the calculated auto size and the grid is not drawing them less than the calculated auto size, even though the grid is telling me that the width that is set on the columns is less than the size they are being drawn at. Only after setting the width and calling refresh TWO more times will I see the correct width.

I've tried the calls with all possible options for AutoResizeType, and with both true and false for includeHeaders, and it's still the same. I tried this in an ancient 2008 version and with the current version of the UltraGrid, and it's still the same. 

Any idea what's going on here?

  • 5315
    Offline posted

    Hello,


    Thank you for posting . 

    There are lots of reasons why the actual column width would not be the Width.
    For example, if you are using RowLayoutStyle.ColumnLayout or RowLayoutStyle.GroupLayout.

    Or if the width you are setting doesn't fit within the MaxWidth and MinWidth on the column. And AutoFitStyle also has an effect.

    Please share the sample to look into it and find what is causing it

    Also, you could just use the MaxWidth to set the width. Or if you need it to be more dynamic, then you can use BeforeAutoSizeColumn /AfterAutoSizeColumn
    event.

    The best way for us to assist you is if you provide a small isolated sample that we can run and find the cause of this behavior.

    Please let me know if you need further assistance.

    Sincerely,
    Divya Jain
    Associate Software Developer