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

Column Widths

6 Answers 876 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Afaan
Top achievements
Rank 1
Afaan asked on 15 Dec 2008, 08:50 PM
Hi, i am having some trouble setting the appropriate sizes for a radgridview columns. I am using the radgridview as a seperate user control, and loading that user control into one of many radchildforms for an mdi application. Th problem is however that when the gridview is loaded into the radchild from, i would like it to fill the entire child form. I have tried using 

this

 

.radGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

But the problem with that is it automatically sizes the columns to be all equal which is not suitable for this application. And in this case giving each column a fixed length is also not an option as this application needs to run on several resolutions. When i tried using 

 this.radGridView1.MasterGridViewTemplate.BestFitColumns(); 

The columns only appear on part of the child form(ie if the user resizes the child form, the columns do not resize with it). So if you could please let me know if there is a workaround. Thanks in advance.

 

 

 

 

 

 

 

6 Answers, 1 is accepted

Sort by
0
erwin
Top achievements
Rank 1
Veteran
Iron
answered on 15 Dec 2008, 10:09 PM
Afaan, I've also experiementd with the various settings since my app makes heavy use of the grid.

Here's what I came up with:

I use BestFitColumns() for initial setup of the grid (with the exception of columns that can have a very varying width - in that case I try to determine Width based "average" string and current Font metrics.
As you mentioned, this leads to horizontal scrollbar if the grid is too small or empty space if the containing control is too large.

However, if the user has configured the grid differently (column chooser, changed column position, grouping, column sizes) I persist this information with a unique key that leads to the particular grid and try to restore according to this information (column widths changed proportionally if the containing window has a different size than when persisting the layout info).

If your user base has varying screen formats ( I have everything from 14 to 30 inch),
IMHO it's best to let the user configure each grid for optimal display and persist that configuration.

I'm currently not using the built-in Layout persistence functions but have written my own, due to problems in earlier versions. Consider switching to the standard functions if only telerik would get the column width handling right again. In 2008Q3/2008Q3SP1 there are several bugs with columns not being inserted at the right place or having wrong width when the width was set within BeginUpdate/EndUpdate.

Regards
Erwin



0
Jack
Telerik team
answered on 16 Dec 2008, 10:51 AM
Erwin, thank you for your suggestions.

Afaan,

By default the grid columns are set to default width of 50 pixels. When AutoSizeColumnsMode is set to Fill their width is changed proportionally to fit in grid's client area. This is the main reason to have an equal column width. You could change the width for some of the columns before changing the AutoSizeColumnsMode. You should also set the Dock or Anchor properties of RadGridView in order to synchronize grid's size with the size of the form.

Please open a support ticket and send us your sample application if your need further assistance. This will help finding the best solution for this case.

I would be glad helping you further.

Kind regards,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Afaan
Top achievements
Rank 1
answered on 17 Dec 2008, 01:27 PM
Hi Erwin, thanks for your reply. Now you said something about letting the user decide on a layout and persisting of that configuration, how would i accomplish that? I was not aware that this functionality is available.
 
Jack, thanks for your reply as well. I have set the gridview's dock property to fill inside the user control, as well as set the user control's dock property to fill inside the radchildform. But as i said the results are still no different.

I have thought of another workaround, using the BestFitColumns() function, the results are very close to what i would like. But only problem is as i said there is a lot of blank space after the last column. Is there anyway to just extend the last column to end of the child form?
0
Accepted
erwin
Top achievements
Rank 1
Veteran
Iron
answered on 17 Dec 2008, 04:18 PM
Afaan,

have a look at LoadLayout / SaveLayout Methods of the grid control.

As for having the last column extend more, call BestFitColumns(),  then iterate over all columns but the last one and calculate their combined width. Now it's easy to set the width of the last column to the difference between combined width and width of the containing control. You may have to adjust slightly for margins and padding etc.

Regards
Erwin
0
Afaan
Top achievements
Rank 1
answered on 17 Dec 2008, 07:05 PM
Thanks! That works for now(extending the last column to the edge). I will further look into the save/load layout functions as well. But for now this works. 

On a side note, would you  happen to know how to disable the scroll bars, both the horizontal and vertical ones. Thanks in advance.
0
Jack
Telerik team
answered on 19 Dec 2008, 05:05 PM
Hi Afaan,

I am glad to hear that the issue with the layouts in RadGridView has been resolved.

You can disable the scroll bars in the grid through setting the HorizontalScrollState and VerticalScrollState properties. Consider the code below:

this.radGridView1.MasterGridViewTemplate.HorizontalScrollState = ScrollState.AlwaysHide; 
this.radGridView1.MasterGridViewTemplate.VerticalScrollState = ScrollState.AlwaysHide; 

Should you have any other questions, do not hesitate to write us.

Kind regards,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Afaan
Top achievements
Rank 1
Answers by
erwin
Top achievements
Rank 1
Veteran
Iron
Jack
Telerik team
Afaan
Top achievements
Rank 1
Share this question
or