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

Initial Header Column Width

3 Answers 245 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jose Simas
Top achievements
Rank 2
Jose Simas asked on 19 Apr 2011, 10:43 AM
Hi,

I have a GridView bound to a DataTable. When the data is loaded each column appears to be sized to the width of the name of the column. Is it possible to change this behaviour so that the width of the column is determined by the widest data item (the value in the cells) of that column instead?

Cheers,
Jose

3 Answers, 1 is accepted

Sort by
0
Accepted
Vanya Pavlova
Telerik team
answered on 19 Apr 2011, 12:52 PM
Hi Jose,

 
You are right, by default the ColumnWidth property of RadGridView is set to SizeToHeader, it will size the cells according to the column header and SizeToCells will size the cells according to the cells content.
You may change it as shown below:

this.radgridView.ColumnWidth = GridViewLength.SizeToCells;

Kind regards,
Vanya Pavlova
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
Jose Simas
Top achievements
Rank 2
answered on 19 Apr 2011, 01:57 PM
Hi Vanya,

Thanks for that. I applied the SizeToCells to my grid successfully. But I also need to align the cells to the right and give them a minimum width which I am doing by applying a style:

<Style TargetType="{x:Type telerik:GridViewCell}">
    <Style.Setters>
        <Setter Property="MinWidth" Value="65"/>
        <Setter Property="HorizontalAlignment" Value="Right"/>
    </Style.Setters>
</Style>

But when I added the MinWidth setter to the style the HorizontalAlignment setter no longer works and my text is all aligned to the left. Is there a different way to apply a MinWidth for the columns in conjuction with the SizeToCells? Am I doing something wrong here?

Thanks,
Jose 
0
Accepted
Vanya Pavlova
Telerik team
answered on 19 Apr 2011, 02:06 PM
Hello Jose,


Due to the template structure of GridViewCell, If you need to specify the alignment of the cell within a style use the HorizontalContentAlignment/VerticalContentAlignment properties instead:

<Style TargetType="{x:Type telerik:GridViewCell}">
    <Style.Setters>
        <Setter Property="MinWidth" Value="65"/>
        <Setter Property="HorizontalContentAlignment" Value="Right"/>
    </Style.Setters>
</Style>


Furthermore you may just specify the TextAlignment property of a column in RadGridView.


Kind regards,
Vanya Pavlova
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
Jose Simas
Top achievements
Rank 2
Answers by
Vanya Pavlova
Telerik team
Jose Simas
Top achievements
Rank 2
Share this question
or