This is a migrated thread and some comments may be shown as answers.

adjust the width to the grid

1 Answer 104 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andre
Top achievements
Rank 1
Andre asked on 01 Feb 2019, 01:35 PM
how can i adjust the width of the group to the grid ?
thank you very much.

1 Answer, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 04 Feb 2019, 11:02 AM
Hello Andre,

Thank you for writing.

The width of the group row is calculated dynamically while printing the control. The print layout can be customized with a custom renderer if you override the GetRowSize method: 
private void radButton1_Click(object sender, EventArgs e)
{
    MyGridPrintStyle style = new MyGridPrintStyle();
    this.radGridView1.PrintStyle = style;
    this.radGridView1.PrintPreview();
}
 
public class MyGridPrintStyle : GridPrintStyle
{
    protected override BaseGridPrintRenderer InitializePrintRenderer(RadGridView grid)
    {
        return new MyTableViewDefinitionPrintRenderer(grid);
    }
}
 
public class MyTableViewDefinitionPrintRenderer : TableViewDefinitionPrintRenderer
{
    public MyTableViewDefinitionPrintRenderer(RadGridView grid)
        : base(grid)
    { }
 
    Size rowSize = Size.Empty;
 
    protected override Size GetRowSize(GridViewRowInfo row, TableViewRowLayout rowLayout)
    {
        if (!(row is GridViewGroupRowInfo))
        {
            return base.GetRowSize(row, rowLayout);
        }
 
        if (this.rowSize == Size.Empty)
        {
            int width = 0;
            int height = rowLayout.GetRowHeight(row) + this.GridView.TableElement.RowSpacing;
 
            foreach (GridViewColumn col in rowLayout.RenderColumns)
            {
                if (col is GridViewRowHeaderColumn || col is GridViewIndentColumn)
                {
                    continue;
                }
 
                TableViewCellArrangeInfo info = rowLayout.LayoutImpl.GetArrangeInfo(col);
 
                if (info == null)
                {
                    continue;
                }
 
                int cellWidth = rowLayout.GetColumnWidth(col);
 
                if (width != 0)
                {
                    cellWidth += this.GridView.TableElement.CellSpacing;
                }
 
                width += cellWidth;
            }
 
            this.rowSize = new Size(width, height);
        }
 
        return this.rowSize;
    }
}

Generally speaking the group row in your screenshot should have a width equalling the width of the data row. In case you will be needing further assistance, please provide me with more information about your local setup and with details how the behavior on your end can be reproduced.

Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Andre
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or