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

How to AutoSize GridView Column Header

7 Answers 851 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Asp
Top achievements
Rank 1
Asp asked on 24 May 2012, 07:35 PM
I m using radgridview. I want to auto size the every column by its header text automatically. Is it possible.

Please help.

7 Answers, 1 is accepted

Sort by
0
Smith
Top achievements
Rank 1
answered on 25 May 2012, 11:42 AM
Hi Asp,

Can I see your code or screenshot?

or you may try this code below.

radGridView1.MasterTemplate.BestFitColumns();
0
Asp
Top achievements
Rank 1
answered on 28 May 2012, 04:00 PM
Hi Smith,
             I m working on a winform. I m using RadGridView to show data from a table.
Now the problem i m having is. the column header in my table are too long. eg. ColumnHeaderOne, ColumnHeadertwO.

When i run my form i m not able to view full column  name. they are appearing like this. ColumnHead..| ColumnHead..|
is there any way i can put the column header at autosize.

 
0
Smith
Top achievements
Rank 1
answered on 28 May 2012, 05:10 PM
Hello Asp,

how you use the RadGridView?
are you add column by code or use the RadGridView property builder?

if you add column by code, please make sure that you put the code I mention earlier after you finish generate column.

[the mention code is radGridView1.MasterTemplate.BestFitColumns();]

However, if you use RadGridView property builder in design, I barely remember that there is a property to set. (need to check). will get back to you later :)


0
Asp
Top achievements
Rank 1
answered on 28 May 2012, 07:22 PM
Hi Smith, I m dynamically binding the grid with data source. The column are auto generated  on the basics of  the column i have in table.
I was going through the suggestions you made but i was not able to find the propriety you said. But i when i changed AutoSizeColumnMode to Fill from None I am somehow able to autofit the column now. 
0
Boryana
Telerik team
answered on 29 May 2012, 10:28 AM
Hello Asp,

Thank you for writing.

As Smith Lo suggested, the correct approach to auto size each column depending on its header cell size is through using the BestFitColumns() method of the specific RadGridView template. This method works regardless of the number of columns, their origin (autogenerated or manually added), or grid mode (bound, unbound, mixed). More information on the BestFit algorithm can be found here: http://www.telerik.com/help/winforms/gridview-columns-resizing-columns-programatically.html.

Since you have mentioned that the above suggestion does not work in your case, I kindly ask to you provide us with a sample project that illustrates the issue. In this way our team will be able to analyze the wrong behavior and provide you with proper support. I have converted your other forum post on the same topic to a support ticket in order to allow attachments. You will be able to find it in your Telerik account. Please transfer any further discussion there.

Regards,
Boryana
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Fatima
Top achievements
Rank 1
answered on 23 Aug 2012, 02:51 PM
Hi,

i m using Radtreelistview and i want autosize column ,the methode BestFitColumns does'nt exist


0
Boryana
Telerik team
answered on 27 Aug 2012, 02:56 PM
Hello Fatima,

Please note that the current thread is devoted to the auto size functionality of the WinForms RadGridView control. Please post here only relevant queries.

The RadTreeListView control is not part of the WinForms suite. You have already opened a new thread in the correct forum (WPF), so please wait for our answer there: http://www.telerik.com/community/forums/wpf/treelist/radtreelistview-autosize.aspx.

Regards,
Boryana
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Asp
Top achievements
Rank 1
Answers by
Smith
Top achievements
Rank 1
Asp
Top achievements
Rank 1
Boryana
Telerik team
Fatima
Top achievements
Rank 1
Share this question
or