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

Column Header template on dynamic colums

3 Answers 197 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 31 Jan 2012, 02:50 AM
I am using your data table construct to populate a grid with dynamic structured data.

Data structure snaffled from:
http://blogs.telerik.com/vladimirenchev/posts/09-04-23/lightweight_datatable_for_your_silverlight_applications.aspx

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}" />

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 31 Jan 2012, 10:47 AM
Hi Mark ,

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


Kind regards,
Pavel Pavlov
the Telerik team

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

0
Mark
Top achievements
Rank 1
answered on 01 Feb 2012, 01:04 AM
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.
0
Mark
Top achievements
Rank 1
answered on 13 Feb 2012, 07:49 AM
Pavlov
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">
            <Setter.Value>
                <ControlTemplate TargetType="telerik:GridViewHeaderCell">
                    <TextBlock Text="{Binding Column.UniqueName}" TextWrapping="Wrap" Height="Auto" TextAlignment="Left"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>      
        <Setter Property="Height" Value="Auto" />
    </Style>

Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Mark
Top achievements
Rank 1
Share this question
or