Unplanned
Last Updated: 26 Mar 2018 11:38 by ADMIN
ADMIN
Dimitar
Created on: 27 Mar 2017 08:32
Category: GridView
Type: Bug Report
4
FIX. RadGridView - incorrect row height when the rows are auto-sized and the font is changed.
Use attached project to reproduce!

Another case is when the font size is changed from the settings dialog - in this case, the row height is not adjusted.

Workaround:
Use the following custom print style:

class MyTableViewDefinitionPrintRenderer : TableViewDefinitionPrintRenderer
{
    public MyTableViewDefinitionPrintRenderer(RadGridView grid) : base(grid)
    {

    }
    protected override int GetDataRowHeight(GridViewRowInfo row, TableViewRowLayoutBase rowLayout)
    {
        int result = base.GetDataRowHeight(row, rowLayout);

        int newHeight = 0;

        if (!(row is GridViewGroupRowInfo))
        {
            foreach (GridViewColumn col in row.ViewTemplate.Columns)
            {
                if (col is GridViewRowHeaderColumn || col is GridViewIndentColumn || !col.IsVisible)
                {
                    continue;
                }

                string value = row.Cells[col.Name].Value.ToString();

                TableViewCellArrangeInfo info = ((TableViewRowLayout)rowLayout).LayoutImpl.GetArrangeInfo(col);
                float cellWidth = (float)info.CachedWidth;
                int currentHeight = TextRenderer.MeasureText(value, this.GridView.PrintStyle.CellFont, new Size((int)cellWidth, 0), TextFormatFlags.WordBreak).Height + this.GridView.Font.Height *4;

                newHeight = Math.Max(newHeight, currentHeight);

            }
        }


        return Math.Max(newHeight, result); 
    }
}
class MyPrintStyle :GridPrintStyle
{
    protected override BaseGridPrintRenderer InitializePrintRenderer(RadGridView grid)
    {
        return new MyTableViewDefinitionPrintRenderer(grid);
    }
}
Attached Files:
4 comments
ADMIN
Dimitar
Posted on: 26 Mar 2018 11:38
Hi Max,

I am sorry for the late responce. We had issueswith the notification system. Nevertheless, I have investigated this again and it appears that there is a better way of measuring the text. Here it is:

LightVisualElement l = new LightVisualElement() { Font = this.GridView.PrintStyle.CellFont, Text = value, TextWrap = true, AutoEllipsis = true };
int currentHeight = (int)Math.Round(MeasurementControl.ThreadInstance.GetDesiredSize(l, new SizeF(cellWidth, float.MaxValue)).Height, MidpointRounding.AwayFromZero);
if (currentHeight > 80)
{
    currentHeight += this.GridView.PrintStyle.CellFont.Height;
}
newHeight = Math.Max(newHeight, Math.Max(currentHeight, this.GridView.Font.Height));

I hope this will be useful. 
Max
Posted on: 06 Sep 2017 20:00
Hi Dimitar!

I have more one issue about this case...

When rows are printed, the workaround used make grid rows more larger, same when not is necessary (in case of one row with few text).
I need that rows stay with a better size, because when I have a report with many lines, occurs that many pages are generated unnecessary.

Can you help me?

Use attached project to reproduce!

Thanks in advance.
Attached Files:
ADMIN
Dimitar
Posted on: 15 Aug 2017 13:42
Hi Max,

Unfortunately, there is no workaround for this case and you should wait for the official fix. 

Regards, 
Dimitar
Max
Posted on: 22 Jun 2017 20:41
Hi Dimitar!

I used your implementation in this test project and this solution works perfectaly! Thanks!

But, When I click on "Print Settings" button and I choose the landscape orientation option and I click on "Preview", the issue occurs again. It seems like preview it loses the initial configurations made in MyPrintStyle class...

How I can to use a workaround for this issue?

Best regards,
Max