Auto width GridView based on content

5 posts, 0 answers
  1. Chris
    Chris avatar
    3 posts
    Member since:
    May 2011

    Posted 27 May 2011 Link to this post

    Hey there-
    I am attempting to AutoFit my GridView in a DockPanel, which is causing me difficulties. I have not set a height or width, but I have set a minimum and maximum width for when it resizes. My question is what snippet of code is need in order to AutoFit the GridView in a DockPanel. 
    Thanks in advance,
    Chris

  2. Dimitrina
    Admin
    Dimitrina avatar
    3193 posts
    Member since:
    Dec 2014

    Posted 30 May 2011 Link to this post

    Hi Chris,

    As I understand your question, you want the GridView to AutoFit the DockPanel.
    In order to AutoFit in a container panel, like DockPanel, you should set Width="Auto". This way when you resize the container, the GridView will follow the it, filling it.

    If you want your columns' width to resize appropriately to the GridView width, you may use ColumnWidht="*".

    <DockPanel Background="BlanchedAlmond">
            <telerik:RadGridView Name="playersGrid" Width="Auto" ColumnWidth="*">
            </telerik:RadGridView>
    </DockPanel>

    Could you please share with us, if this suggestion is answering your question?

    Kind regards,
    Didie
    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

  3. Download a free trial of UI for WPF
  4. Chris
    Chris avatar
    3 posts
    Member since:
    May 2011

    Posted 31 May 2011 Link to this post

    Didie-
    This did not solve my issue, so let me try to explain as best as I can. I am using a Telerik GridView control inside of a DockPanel, which is inside of a Grid in Expression Blend 4 (not a telerik grid). All of my content and controls have no issue auto-sizing to the width of the window, as I have set the width and relative margins of all other content areas. But the Telerik GridView only fills up about 1/2 of the width of the screen...when I set the size of the GridView to Width="Auto" or ColumnWidth="*" the GridView does start to take up the remainder of the width...but it does not resize in the relation to the rest of the content when the window is resized. This completely defeats the purpose of trying to autosize based on content. Am I missing something here, or perhaps doing something wrong?
    Thanks for your assistance,
    Chris

    <DockPanel x:Name="DockPanel_Row3" LastChildFill="False" Margin="5,0,0,0" VerticalAlignment="Top" Grid.Row="2" Grid.ColumnSpan="3"  Grid.Column="0" MaxWidth="680" HorizontalAlignment="Left" MinWidth="446" Width="Auto">
                <telerik:Label Content="Subcommittee Members" Height="20" VerticalAlignment="Top" HorizontalAlignment="Left" Padding="0,3,5,3" DockPanel.Dock="Top" Margin="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />
                <telerik:RadGridView x:Name="grMembers" Margin="0" VerticalAlignment="Top" Width="Auto" ColumnWidth="*"
                    ItemsSource="{Binding MemberList}"
                    AutoGenerateColumns="True" VerticalContentAlignment="Stretch" DockPanel.Dock="Bottom" HorizontalContentAlignment="Stretch" MinWidth="446" MaxWidth="900" GroupPanelBackground="{DynamicResource GridViewDragHeader}" BorderBrush="{DynamicResource GridViewDragHeaderStroke}"/>
            </DockPanel>

  5. Dimitrina
    Admin
    Dimitrina avatar
    3193 posts
    Member since:
    Dec 2014

    Posted 01 Jun 2011 Link to this post

    Hi Chris,

    I notice that you add Min and Max Width and then AutoSize to the DockPanel and the GridView. This means that the controls will AutoSize between the MInWidth and the MaxWidth only. You set MaxWidth of the GridView="900", but the maximum that it may go is the MaxWidth="680" of the DockPanel. 

    I have captured a video that tries to reproduce the behavior that you reference. Could you please review it and confirm is this the case?

    I have prepared a sample project, showing how the GridView is auto fitting the window resize right, when the Min and MaxWidth is removed. If you prefer to keep the Min and Max width, then they need to correspond to the Min and Max width of the Window, so that when Window resizes, the DockPanel/GridView could resize appropriately.

    Could you please review the sample project and let me know if this is solving your auto fitting problem?

    All the best,
    Didie
    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

  6. Ryan
    Ryan avatar
    2 posts
    Member since:
    Sep 2011

    Posted 19 Sep 2011 Link to this post

    In Design-Time my columns resize like in your video cast. At runtime the columns initially scroll outside the grid which is keeping the same width as the containing Window. The Columns do not resize at runtime. Here is a  Video of my design and runtime experience.

    Edit: Rather than using the MinWidth property I used the * in the column width property ie.. width="100*"

Back to Top
Download a free trial of UI for WPF