2 posts, 1 answers
  1. Mohsen
    Mohsen avatar
    5 posts
    Member since:
    Jun 2014

    Posted 19 Nov 2015 Link to this post

    I need something like BesFitColumns() for rows. I know that I can use AutoSizeRows, but it has problem with cells that have long multiline content. I attached screenshot. Please check it.
  2. Answer
    Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    4170 posts

    Posted 23 Nov 2015 Link to this post

    Hello Mohsen,

    Thank you for writing.

    Due to UI virtualization in RadGridView, auto-size rows mechanism takes into consideration the currently visible cells. That is why when a multiline text is not visible, the row's height is small, but when you show the multiline text while scrolling, the height is adjusted to display the whole cell's content. This is normal behavior. However, you can turn off the auto-size mechanism and measure all cells in a row in order to determine the row's height considering all cells(including the invisible ones as well). You can find below a sample implementation:
    private void Form1_Load(object sender, EventArgs e)
        foreach (GridViewColumn col in this.radGridView1.Columns)
            col.WrapText = true;
        this.radGridView1.AutoSizeRows = false;
        this.radGridView1.Columns["CompanyName"].IsPinned = true;
        this.radGridView1.Columns["Phone"].IsPinned = true;
    private void AdjustRowHeight()
        RowElementProvider rowProvider = (RowElementProvider)this.radGridView1.TableElement.RowElementProvider;
        CellElementProvider cellProvider = (CellElementProvider)this.radGridView1.TableElement.CellElementProvider;
        foreach (GridViewRowInfo row in this.radGridView1.Rows)
            row.Height = (int)GetRowHeight(this.radGridView1, rowProvider, cellProvider, row);
    public double GetRowHeight(RadGridView radGridView, RowElementProvider rowProvider, CellElementProvider cellProvider,
        GridViewRowInfo gridViewRowInfo)
        double rowHeight = 0;
        GridRowElement visualRow = rowProvider.GetElement(gridViewRowInfo, null) as GridRowElement;
        foreach (GridViewColumn col in visualRow.ViewTemplate.Columns)
            if (col is GridViewRowHeaderColumn || col is GridViewIndentColumn)
            GridCellElement cell = cellProvider.GetElement(col, visualRow) as GridCellElement;
            cell.Initialize(col, visualRow);
            GridHeaderCellElement headerCell = cell as GridHeaderCellElement;
            if (headerCell != null)
            cell.Measure(new System.Drawing.SizeF(cell.ColumnInfo.Width, float.PositiveInfinity));
            rowHeight = Math.Max(rowHeight, cell.DesiredSize.Height);
            ReleaseCellElement(cellProvider, visualRow, cell);
        ReleaseRowElement(radGridView, rowProvider, visualRow);
        return rowHeight;
    void ReleaseRowElement(RadGridView radGridView, RowElementProvider rowProvider, GridRowElement rowElement)
    void ReleaseCellElement(CellElementProvider cellProvider, GridRowElement rowElement, GridCellElement cell)
        GridVirtualizedCellElement virtualizedCell = cell as GridVirtualizedCellElement;
        if (virtualizedCell != null)

    I hope this information helps. Should you have further questions I would be glad to help.
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top