Adjust height of RadGridView automatically

13 posts, 0 answers
  1. Red
    Red avatar
    1 posts
    Member since:
    Oct 2008

    Posted 16 Apr 2009 Link to this post

    Hi,

    I have a grid which is populated as certain things happen within the application (e.g. as validation errors happen).

    I have the grid at the top of a final wizard screen and want to be able to stack other controls underneath it (using docking).

    Thus I need to be able to auto adjust the height of the grid so that it takes up only the exact amount of space required to show the rows + headers + padding / border.

    I would have expected there to be a property such as the normal: "AutoSize" and "AutoSizeMode = AutoSizeMode.GrowAndShrink".

    I would rather avoid adding a RowsChanged and RowHeightChanged handlers to iterate and calculate the total height... If this is the way forward, please provide and example with all the elements of the grid that should be taken into account.

    There is only a single level of data and grouping is not enabled (but I can't get the group by box to go away!).

    Cheers,
    Andrew.
  2. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 21 Apr 2009 Link to this post

    Hello Red,

    Thank you for contacting us.

    I understand your scenario. Currently RadGridView doesn't support auto size mode. We will consider implementing this feature in one of our upcoming releases. You should handle the RowsChanged event in this case. Unfortunately, there is no RowHeightChanged event in RadGridView. Here is a sample:

    void radGridView1_RowsChanged(object sender, GridViewCollectionChangedEventArgs e) 
        if (e.Action == NotifyCollectionChangedAction.Add || 
            e.Action == NotifyCollectionChangedAction.Remove) 
        { 
            UpdateHeight(); 
        } 
     
    private void UpdateHeight() 
        int height = 0; 
     
        foreach (GridViewDataRowInfo row in this.radGridView1.Rows) 
        { 
            height += row.GetActualHeight(this.radGridView1.GridElement); 
        } 
        if (this.radGridView1.MasterGridViewTemplate.AllowAddNewRow && !this.radGridView1.ReadOnly) 
        { 
            height += this.radGridView1.MasterGridViewInfo.TableAddNewRow.GetActualHeight(this.radGridView1.GridElement); 
        } 
        if (this.radGridView1.EnableFiltering) 
        { 
            height += this.radGridView1.MasterGridViewInfo.TableFilteringRow.GetActualHeight(this.radGridView1.GridElement); 
        } 
        if (this.radGridView1.MasterGridViewTemplate.ShowColumnHeaders) 
        { 
            height += this.radGridView1.MasterGridViewInfo.TableHeaderRow.GetActualHeight(this.radGridView1.GridElement); 
        } 
        height += 20; // horizontal scroll bar height 
     
        this.radGridView1.Height = height; 

    The RowsChanged event isn't fired when loading the grid. So, you should call this method explicitly.

    Set the ShowGroupPanel property to false to hide the grouping panel:

    this.radGridView1.ShowGroupPanel = false
     

    I hope this helps. If you have any further questions, I will be glad to help.

    Greetings,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. [Nean]
    [Nean] avatar
    42 posts
    Member since:
    Mar 2009

    Posted 06 May 2010 Link to this post

    Hi Jack,

    Is the auto size mode implemented in the new Q1 2010 version or is it for soon ? I work on a project wihch needs this behaviour and your workaround take too much time for quite old computers...

    Thanks,

    [Nean]
  4. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 10 May 2010 Link to this post

    Hi [Nean],

    I understand your position. However, we have not received more requests for this feature and it is not in our most immediate plans. I can't give you a time frame when or whether it will be implemented.

    Should you have any other questions, please write back.

    Kind regards,
    Jack
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.
  5. Abhay
    Abhay avatar
    11 posts
    Member since:
    Jan 2011

    Posted 27 May 2011 Link to this post

    Hi Jack,

    Has Telerik enabled RadGridView to adjust its height automatically based on the number of rows in any of their later releases? If yes, can you tell us how. We're currently using the 2011 Q1 version.

    ~Abhay
  6. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 28 May 2011 Link to this post

    Hello Abhay,

    Thank you for this question.

    Yes, it was implemented in our Q3 2010 release. All you need is to set the AutoSize property to true. Be aware that when this property is set to true and you do not have rows in RadGridView, then its size will be empty.

    If you need further assistance with this, I will be glad to assist you.

    Best wishes,
    Jack
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  7. Abhay
    Abhay avatar
    11 posts
    Member since:
    Jan 2011

    Posted 31 May 2011 Link to this post

    Hello Jack.

    Thanks for your prompt reply.

    I tried to use AutoSize property by setting it to TRUE. But I think, this property will resize the grid both horizontally and vertically in contrast to my requirement of ONLY adjusting the height based on the number of rows.

    Can you please tell me if there is a way to fix the width but still let the height change based on the number of rows?

    ~Abhay
  8. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 03 Jun 2011 Link to this post

    Hello Abhay,

    Yes, this is possible by setting MinimumSize and MaximumSize properties. Please consider the following sample:
    this.radGridView1.AutoSize = true;
    this.radGridView1.MinimumSize = new Size(200, 0);
    this.radGridView1.MaximumSize = new Size(200, 0);

    I hope this helps.

    Best wishes,
    Jack
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  9. Abhay
    Abhay avatar
    11 posts
    Member since:
    Jan 2011

    Posted 03 Jun 2011 Link to this post

    Thanks Jack.

    I had thought so. Just wanted to get it confirmed because I was wary of introducing any side-effects by using the MinimumSize and MaximumSize properties.

    ~Abhay

  10. Gavin
    Gavin avatar
    3 posts
    Member since:
    Oct 2016

    Posted 11 Nov 2016 in reply to Jack Link to this post

    Hi Jack.

    I have tried to use your solution by using the RowsChanged event, but there doesn't seem to be such an event for RadGridView. If there is, then the intellisense in Visual Studio is not picking it up. Has this event been deleted in more recent releases of Telerik since you posted this solution?

    Gavin

  11. Dimitar
    Admin
    Dimitar avatar
    2728 posts

    Posted 11 Nov 2016 Link to this post

    Hi Gavin,

    Thank you for writing.

    The RowsChanged event is not removed. Please note taht this forum is for the WinForms suite. 

    In addition the following article contains information about this event: Tracking changes in RadGridView.

    Please do not hesitate to contact us with any additional questions or concerns. 
     
    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  12. mahesh
    mahesh avatar
    1 posts
    Member since:
    Nov 2017

    Posted 19 Dec 2017 Link to this post

    Hi,

     want to auto size row height based on text of cell on wrap.. Didn't find Autorowsize property, can you please help on this.

  13. Dimitar
    Admin
    Dimitar avatar
    2728 posts

    Posted 20 Dec 2017 Link to this post

    Hi Mahesh,

    You can use the following property:
    radGridView1.AutoSizeRows = true;

    I hope this will be useful. 

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top