Column Header template on dynamic colums

4 posts, 0 answers
  1. Mark
    Mark avatar
    61 posts
    Member since:
    Dec 2010

    Posted 30 Jan 2012 Link to this post

    I am using your data table construct to populate a grid with dynamic structured data.

    Data structure snaffled from:

    I now need to wrap the text in the column header. I have the following in the code behind to remove the xml space.
    private void GridLoaded(Code.AppMessages.ListCompleteMessage.enMessage eMessage)
        if (eMessage == Code.AppMessages.ListCompleteMessage.enMessage.GenericTable)
            foreach (GridViewColumn oCol in RGV1.Columns)
                oCol.Header = oCol.Header.ToString().Replace("_x0020_", " ");
                oCol.MaxWidth = 200;
                oCol.TextWrapping = TextWrapping.Wrap;

    I have no preference as to using a xaml template or code behind. I just can't work out the template structure or get at the text wrapping from the code. This is the xaml.
    <telerik:RadGridView x:Name="RGV1" RowIndicatorVisibility="Collapsed" IsReadOnly="True"
                                CanUserFreezeColumns="False" ShowColumnFooters="True" ShowGroupFooters="True" CanUserResizeColumns="False"
                                ItemsSource="{Binding ReportTable,Mode=OneWay}" />

  2. Pavel Pavlov
    Pavel Pavlov avatar
    2039 posts

    Posted 31 Jan 2012 Link to this post

    Hi Mark ,

    Here is a RadGridView with a column with text wrapping in the header.
    <telerik:RadGridView x:Name="RadGridView1" >
                    <telerik:GridViewDataColumn >
                            <TextBlock Text="Lorem Ipsum dolor Sin Amet" TextWrapping="Wrap" />

    Kind regards,
    Pavel Pavlov
    the Telerik team

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

  3. Mark
    Mark avatar
    61 posts
    Member since:
    Dec 2010

    Posted 31 Jan 2012 Link to this post

    Pavel you seemed to have missed the critical point that the columns are DYNAMIC therefore your example is not valid. I have to either apply a style to the column header from the code behind or use a template for the header row applied to the RadGridView, NOT the individual columns.
  4. Mark
    Mark avatar
    61 posts
    Member since:
    Dec 2010

    Posted 13 Feb 2012 Link to this post

    Having had another go at this issue I have managed to bind the header text to the Column.UniqueName using a control template but I cannot get the textwrapping to work.

    <!--This style is not working!-->
        <Style x:Key="TelerikHeaderCellStyle" TargetType="telerik:GridViewHeaderCell">     
            <Setter Property="Template">
                    <ControlTemplate TargetType="telerik:GridViewHeaderCell">
                        <TextBlock Text="{Binding Column.UniqueName}" TextWrapping="Wrap" Height="Auto" TextAlignment="Left"/>
            <Setter Property="Height" Value="Auto" />

Back to Top