How to Auto-Size RadGridView's Rows

Environment

Product Version 2019.1.220
Product RadListBox for WPF

Description

How to auto-size the rows of the RadGridView control based on its height.

Solution

  1. Define the following method in the code-behind of the control which holds your RadGridView instance:

    private void AdjustRowHeight() 
    { 
        var scrollViewer = this.radGridView.ChildrenOfType<GridViewScrollViewer>().First(); 
        double rowHeight = (scrollViewer.ActualHeight - scrollViewer.HeaderRow.ActualHeight) / this.radGridView.Items.Count; 
        if (rowHeight > 0) 
        { 
            this.radGridView.RowHeight = rowHeight; 
        } 
    } 
    
    What this does is to get the actual height of the GridViewScrollViewer - which is the element that holds all the rows of the control - and subtract from it the height of the header row element. This height is then divided by the total row count.
  2. Call the AdjustRowHeight method in the Loaded and SizeChanged events of the RadGridView control:

    private void RadGridView_Loaded(object sender, RoutedEventArgs e) 
    { 
        this.AdjustRowHeight(); 
    } 
     
    private void RadGridView_SizeChanged(object sender, SizeChangedEventArgs e) 
    { 
        this.AdjustRowHeight(); 
    } 
    

    See Also

  3. ChildrenOfType
In this article
Not finding the help you need? Improve this article