adjust the width to the grid

2 posts, 1 answers
  1. Andre
    Andre avatar
    41 posts
    Member since:
    Feb 2018

    Posted 01 Feb 2019 Link to this post

    how can i adjust the width of the group to the grid ?
    thank you very much.
  2. Answer
    Hristo
    Admin
    Hristo avatar
    1517 posts

    Posted 04 Feb 2019 Link to this post

    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.
Back to Top