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

Column auto width issue

7 Answers 157 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Trude
Top achievements
Rank 2
Trude asked on 07 Oct 2010, 11:09 AM
I have the following XAML:
<telerik:RadGridView x:Name="RadGrid1" Grid.Row="1" IsReadOnly="True" SelectionChanged="RadGrid1_SelectionChanged" RowDetailsVisibilityMode="VisibleWhenSelected" IsSynchronizedWithCurrentItem="True" FontFamily="Arial" FontSize="14" AutoGenerateColumns="False" IsFilteringAllowed="False" SelectionMode="Single" ShowGroupPanel="False" CanUserReorderColumns="False" CanUserFreezeColumns="False" Margin="1">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding name}" Width="*">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{Binding LocStr.Name, Source={StaticResource LocStr}}" Style="{StaticResource TextBlockNormal}"/>
            </telerik:GridViewDataColumn.Header>
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Converter={StaticResource SurveyStatus}, Path=status}" Width="Auto">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{Binding LocStr.Status, Source={StaticResource LocStr}}" Style="{StaticResource TextBlockNormal}"/>
            </telerik:GridViewDataColumn.Header>
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding start_date, StringFormat=\{0:d\}}" Width="Auto">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{Binding LocStr.Start_date, Source={StaticResource LocStr}}" Style="{StaticResource TextBlockNormal}"/>
            </telerik:GridViewDataColumn.Header>
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding end_date, StringFormat=\{0:d\}}" Width="Auto">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="{Binding LocStr.End_date, Source={StaticResource LocStr}}" Style="{StaticResource TextBlockNormal}"/>
            </telerik:GridViewDataColumn.Header>
        </telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

That is; one star (*) column and the rest are set to auto. See attached screenshot for output.
Why is the last column truncated? If I resize the usercontrol (it's contained within a radwindow) the gridview "snaps" the last column into place (it becomes full-sized)

7 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 13 Oct 2010, 08:42 AM
Hi Jorn,

I could not reproduce the problem in a simple project. Please find it attached and let me know how to reproduce it.

Kind regards,
Veselin 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
0
Trude
Top achievements
Rank 2
answered on 13 Oct 2010, 11:08 AM
I've played around with your sample and I think I discovered the reason for my troubles. Alter the MyViewModel.cs to return an empty collection instead of a populated list:
public ObservableCollection<Club> Clubs
{
    get
    {
        if (this.clubs == null)
        {
            this.clubs = new ObservableCollection<Club>();
        }
        return this.clubs;
    }
}

Alter your SilverlighControl1 code in this way (I added a button in the XAML):
namespace RadGridView_SL4_AR_19
{
    public partial class SilverlightControl1 : UserControl
    {
        private MyViewModel myviewmodel = new MyViewModel();
 
        public SilverlightControl1()
        {
            InitializeComponent();
            RadGrid1.ItemsSource = myviewmodel.Clubs;
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ObservableCollection<Club> _clubs = Club.GetClubs();
            foreach (Club i in _clubs)
            {
                myviewmodel.Clubs.Add(i);
            }
        }
 
    }
}

When the window is first opened the RadGrid is empty. Click the button and the list is populated but the last column is truncated like in my first post.

Here's the RadGrid XAML (date-column last and to better illustrate my scenario):
<telerik:RadGridView x:Name="RadGrid1" Grid.Row="1" IsReadOnly="True"
                     RowDetailsVisibilityMode="VisibleWhenSelected" IsSynchronizedWithCurrentItem="True"
                     FontFamily="Arial" FontSize="14" AutoGenerateColumns="False" IsFilteringAllowed="False"
                     SelectionMode="Single" ShowGroupPanel="False" CanUserReorderColumns="False" CanUserFreezeColumns="False" Margin="1">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Width="*">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="Name"/>
            </telerik:GridViewDataColumn.Header>
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}" Width="Auto" DataFormatString="{}{0:N0}">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="Capacity"/>
            </telerik:GridViewDataColumn.Header>
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Established, StringFormat=\{0:d\}}" Width="Auto">
            <telerik:GridViewDataColumn.Header>
                <TextBlock Text="Est."/>
            </telerik:GridViewDataColumn.Header>                   
        </telerik:GridViewDataColumn>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>
0
Trude
Top achievements
Rank 2
answered on 13 Oct 2010, 11:11 AM
Please note that I've altered the last column's date format to make it wider (not just the year).
0
James
Top achievements
Rank 1
answered on 14 Oct 2010, 11:31 PM

Hi Jorn,

This has been a problem in my application for some time now, I raised the issue back in Januray but a rather crude workaround was suggested.


http://www.telerik.com/community/forums/silverlight/gridview/column-not-auto-sizing-correctly.aspx

I ended up hard coding the column widths in all my grids (except star columns) as Auto does not work - I just checked again with the SP2 release and it is still broken i.e auto columns appear bunched up and not sized to content, as mentioned a resize of the parent container will correct the problem.

Telerik, a fix for this would be great! Hard coding all column sizes (except star columns) is not ideal. As Jorn mentioned, this only occurs when RadGridView is loaded asynchronously - I'm very surprised this has not caused more people headaches, due to the asynchronous nature of Silverlight.

Kind regards,
James

0
Trude
Top achievements
Rank 2
answered on 15 Oct 2010, 09:27 AM
Hello James,

Thanks for chipping in; maybe Telerik will listen now that more (paying) customers are demanding a fix.
I use WCF RIA services to populate most of my controls so this is indeed related to async loading.
On some of the controls I can set Itemssource after the Loaded event, but not all.
0
Veselin Vasilev
Telerik team
answered on 18 Oct 2010, 01:01 PM
Hi Jorn,

I have noticed that if you put a header which text is longer than the values of the cells - the problem does not manifest. Another possible solution would be to show the group panel (ShowGroupPanel="True"). Still, these are more like a dirty workarounds so I have logged the bug in our public issue tracking system for fixing. You can track its progress here.

Regards,
Veselin 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
0
James
Top achievements
Rank 1
answered on 30 Jan 2011, 09:43 AM

This appears to be fixed with Q3 2010 SP1 - columns are now sizing correctly when Width=Auto.

James

Tags
GridView
Asked by
Trude
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
Trude
Top achievements
Rank 2
James
Top achievements
Rank 1
Share this question
or