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

Resize columns to fit window

2 Answers 293 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Peter asked on 11 Apr 2012, 02:36 AM

I'm having difficulty resizing my RadGridView (within a UserControl) to fit within the bounds of the window. My RGV consists of several fixed columns and a few other columns that I'd like to be each a set fraction of the remaining width available. Using the help given in this post, this is my current xaml (simplified):
        <RowDefinition Height="*" />
        <ColumnDefinition Width="*" />
    <telerik:RadGridView ItemsSource="{Binding Source={StaticResource MainRepo}, Path=DvFocusControl}"
                         Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="1" Grid.RowSpan="1"
                         HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
            <telerik:GridViewDataColumn Name="ColAutoNum" Header="#" IsReadOnly="True" MinWidth="50" Width="50" />
            <telerik:GridViewDataColumn Name="ColType" Header="Type" IsReadOnly="True" MinWidth="30" Width="50" />
            <telerik:GridViewDataColumn Name="ColRequest" Header="Request" IsReadOnly="True" MinWidth="80" Width="80" />
            <telerik:GridViewDataColumn Name="ColSubject" DataMemberBinding="{Binding Subject}" Header="Subject" IsReadOnly="True" MinWidth="50" Width="2*" TextWrapping="Wrap"/>
            <telerik:GridViewDataColumn Name="ColAssignedTo" DataMemberBinding="{Binding AssignedTo}" Header="Assigned To" IsReadOnly="True" MinWidth="50" Width="*" MaxWidth="200"/>
            <telerik:GridViewDataColumn Name="ColNotes" DataMemberBinding="{Binding Notes}" Header="Notes" IsReadOnly="True" MinWidth="50" Width="3*" TextWrapping="Wrap"/>
            <telerik:GridViewDataColumn Name="ColDate" DataMemberBinding="{Binding DateAdded}" DataFormatString="dd/MM/yy hh:mm tt" Header="Date" IsReadOnly="True" MinWidth="50" Width="70"/>
            <telerik:GridViewDataColumn Name="ColSite" DataMemberBinding="{Binding Site_Name}" Header="Site" IsReadOnly="True" MinWidth="50" Width="50" />
            <telerik:GridViewDataColumn Name="ColT" Header="T" IsReadOnly="True" MinWidth="70" Width="*" MinWidth="50" Width="50"/>
            <telerik:GridViewDataColumn Name="ColAssignedToFullAbbr" DataMemberBinding="{Binding FullAbbr}" Header="Assigned To" IsReadOnly="True" MinWidth="70" Width="1*"/>
            <telerik:GridViewDataColumn Name="ColReceived" DataMemberBinding="{Binding NotifiedOn}" DataFormatString="dd/MM/yy hh:mm tt" Header="Received" IsReadOnly="True" MinWidth="70" Width="70"/>
            <telerik:GridViewDataColumn Name="ColR" Header="R" IsReadOnly="True" MinWidth="50" Width="50"/>

Currently when the RGV is filled the columns expand past the edge of the window. I'd like them to fit to the window.

Because this is likely related to fitting the RGV to the window, here are further details about the columns:
Columns ColSubject, ColNotes, and ColAssignedToFullAbbr are the variable width columns, with ColNotes taking up the most space, followed by ColSubject, then ColAssignedToFullAbbr. I'm not sure whether functionality exists for this, but I've also put minimum widths for the other columns so that should the variable width columns require more space, space up to a certain amount can be given to them from the other columns. Finally, should the variable width columns still require more space, I'd like the text to wrap, hence I've added TextWrapping="Wrap".

If it matters, I've tried setting a fixed size to the window containing this UserControl, and a similar result occurs.

Any help is appreciated.

2 Answers, 1 is accepted

Sort by
Telerik team
answered on 12 Apr 2012, 09:53 AM

 When you set MinWidth or Width for a column, then this Width cannot be decreased in case the RadGridView Width (or the Width of the containing window) is decreased.
If you set all the column to have '*', or '2*', etc. Width, then the columns will be AutoSized based on the available space.

So the Width of your GridView should be more than the sum of all the fixed Width. Is it?

the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Top achievements
Rank 1
answered on 12 Apr 2012, 11:53 PM
Thanks Didie. I should've tried this before as your suggestion works and produces an acceptable result. The minimum widths must have been messing with the calculating.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Top achievements
Rank 1
Share this question