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

AutoSizeColumnsMode

4 Answers 354 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeroen Eikmans
Top achievements
Rank 1
Jeroen Eikmans asked on 29 Jul 2010, 09:42 AM
Hi,

I have a gridview with 2 columns and the AutoSizeColumnsMode is set to Fill.
The grid's datasource is a LinqToSql query, with both fields being strings and it's set in the Form_Load.

The width of the first column however isn't big enough for either the value or the headertext of that column.
I've tried using BestFitColumn but then both columns get a small width.
Is there some other property or something i need to set?

Below is the definition of the grid.
this.radGridView1.MasterGridViewTemplate.AllowAddNewRow = false;
this.radGridView1.MasterGridViewTemplate.AllowColumnReorder = false;
this.radGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
gridViewTextBoxColumn1.AllowResize = false;
gridViewTextBoxColumn1.AllowSort = false;
gridViewTextBoxColumn1.FieldName = "Ordernumber";
gridViewTextBoxColumn1.HeaderText = "Ordernumber";
gridViewTextBoxColumn1.UniqueName = "OrdernumberColumn";
gridViewTextBoxColumn2.AllowResize = false;
gridViewTextBoxColumn2.FieldName = "OrderProduct";
gridViewTextBoxColumn2.HeaderText = "Product";
gridViewTextBoxColumn2.UniqueName = "OrderProductColumn";
this.radGridView1.MasterGridViewTemplate.Columns.Add(gridViewTextBoxColumn1);
this.radGridView1.MasterGridViewTemplate.Columns.Add(gridViewTextBoxColumn2);
this.radGridView1.MasterGridViewTemplate.EnableGrouping = false;
this.radGridView1.Name = "radGridView1";
this.radGridView1.Padding = new System.Windows.Forms.Padding(0, 0, 0, 1);
this.radGridView1.ReadOnly = true;

4 Answers, 1 is accepted

Sort by
0
Jeroen Eikmans
Top achievements
Rank 1
answered on 02 Aug 2010, 08:54 AM
Anybody an idea?
I would really like to get the AutoSizeColumnMode working so columns don't get this small width, because i can't continue with my app if it doesn't work.
0
Emanuel Varga
Top achievements
Rank 1
answered on 02 Aug 2010, 02:00 PM
Hello Roel,

There is something else you can try, there is an individual BestFit method for each column, (radGridView1.Columns[0].BestFit();) you can try calling this just on some column and leave the rest untouched, this might solve some your problems.

Best regards,
Emanuel Varga

0
Jeroen Eikmans
Top achievements
Rank 1
answered on 02 Aug 2010, 03:10 PM
Hello Emanuel,

Thanks for your reply.
Unfortunatly this didn't fix the problem.

HOWEVER I had a second look at my code (the designer file) and i saw i had the column.AllowResize set to False.
This makes the BestFitColumns to ignore the column.

I didn't want the user to allow resizing of the columns that's why i'd set the AllowResize.
I just found the MasterGridViewTemplate.AllowColumnResize and i've set that one to true. No users can't resize the columns but the BestFitColumns does work.

Thanks again for your help!

Kind regards.
0
Martin Vasilev
Telerik team
answered on 03 Aug 2010, 04:22 PM
Hello Roel Martens,

Actually, AllowResize = false should not prevent the BestFit method from working and when I test it on my side it works as expected. Anyway, I am glad that you have found a solution.

Still, I would like to investigate your case so that we can address any potential issues that could be related to AllowResize and BestFit. For that purpose, please open a new support ticket and send me a sample project.

In addition to what you are after, you can consider setting the MinWidth property of a particular column if you need a size larger than the calculated one:
this.radGridView1.Columns[0].AllowResize = false;
this.radGridView1.Columns[0].MinWidth = 200;
  
this.radGridView1.BestFitColumns();

Do not hesitate to write back again if you have any other questions.

Regards,
Martin Vasilev
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
Tags
GridView
Asked by
Jeroen Eikmans
Top achievements
Rank 1
Answers by
Jeroen Eikmans
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or