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

Adjust height of RadGridView automatically

12 Answers 861 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Red
Top achievements
Rank 1
Red asked on 16 Apr 2009, 06:32 PM
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.

12 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 21 Apr 2009, 01:37 PM
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.
0
[Nean]
Top achievements
Rank 1
answered on 06 May 2010, 11:24 AM
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]
0
Jack
Telerik team
answered on 10 May 2010, 04:04 PM
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.
0
Abhay
Top achievements
Rank 1
answered on 27 May 2011, 11:15 PM
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
0
Jack
Telerik team
answered on 28 May 2011, 12:33 PM
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.
0
Abhay
Top achievements
Rank 1
answered on 01 Jun 2011, 02:04 AM
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
0
Jack
Telerik team
answered on 03 Jun 2011, 08:38 AM
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.
0
Abhay
Top achievements
Rank 1
answered on 03 Jun 2011, 05:48 PM
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

0
Gavin
Top achievements
Rank 1
answered on 11 Nov 2016, 09:51 AM

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

0
Dimitar
Telerik team
answered on 11 Nov 2016, 11:51 AM
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.
0
mahesh
Top achievements
Rank 1
answered on 19 Dec 2017, 03:02 PM

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.

0
Dimitar
Telerik team
answered on 20 Dec 2017, 07:26 AM
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.
Tags
GridView
Asked by
Red
Top achievements
Rank 1
Answers by
Jack
Telerik team
[Nean]
Top achievements
Rank 1
Abhay
Top achievements
Rank 1
Gavin
Top achievements
Rank 1
Dimitar
Telerik team
mahesh
Top achievements
Rank 1
Share this question
or