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

Wrap header text in dynamic structured gridview

6 Answers 221 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 21 Mar 2012, 08:50 AM
I have a radgridView that is based on  a pivot table, that is the number of columns is based on the query and cannot be defined. To do this I use your data table construct, this works fine however I need to wrap the text in the header, it is up to 500 characters long.

My latest attempt to fail is trying to apply a style to the header!

private void GridLoaded(Code.AppMessages.ListCompleteMessage.enMessage eMessage)
{
    if (eMessage == Code.AppMessages.ListCompleteMessage.enMessage.GenericTable)
    {
        RadGridView oDG = this.RGV1;//default to the element pivot
        if (vm.eCurrentView == ViewModels.TreePivotVM.enView.Label)
        {
            oDG = this.RGVLabel;//get the label pivot grid
        }
        foreach (GridViewColumn oCol in oDG.Columns)
        {
 
            oCol.Header = oCol.Header.ToString().Replace("_", " ");                
            if (oCol.DisplayIndex == 0)
            {                      
                oCol.Width = Telerik.Windows.Controls.GridViewLength.Auto;
            }
            else
            {                      
                oCol.MaxWidth = 200;
                oCol.TextAlignment = TextAlignment.Right;
                //oCol.HeaderCellStyle = (Style)Application.Current.Resources["TelerikHeaderCellStyle"];                       
                oCol.CellStyle = (Style)Application.Current.Resources["TelerikReportCellStyle"];                       
            }
        }
    }
}

Any suggestions will be greatly appreciated. I would also like to format the numbers in the cells in columns > 0

6 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 21 Mar 2012, 10:09 AM
Hi Mark ,

Your C# code seems OK. Can you please share the XAML with the style (TelerikHeaderCellStyle) so I can check what might be wrong.
Regarding the number formatting - data columns in RadGridView expose the DataFormatString property.

Regards,
Pavel Pavlov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Mark
Top achievements
Rank 1
answered on 21 Mar 2012, 11:02 AM
Certainly, my xaml skills are sadly lacking!

<!--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>
0
Pavel Pavlov
Telerik team
answered on 21 Mar 2012, 05:46 PM
Hi Mark ,

Thanks for sending the template! Indeed it could be fixed but would involve much heavier XAML.
Can you please first check whether this approach would be applicable to your case ?

Let me know in case this does not work for you.

Kind regards,
Pavel Pavlov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Mark
Top achievements
Rank 1
answered on 22 Mar 2012, 12:57 AM
Thanks Pavel, that approach will not work as I do not have any columns defined in the xaml (autogenerate) and the text is coming from the database.
0
Vlad
Telerik team
answered on 22 Mar 2012, 08:05 AM
Hi,

 Auto-generated columns (and the Header property) can be accessed in AutoGeneratingColumn event. You can apply exactly the same approach for these columns as well. 

Greetings,
Vlad
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Mark
Top achievements
Rank 1
answered on 22 Mar 2012, 08:35 AM
Mutter mutter grumble - dammed event does not fire!

The xaml
<telerik:RadGridView Grid.Row="1" x:Name="RGVLabel" Style="{StaticResource TelerikGridStyle}"
                                AutoGenerateColumns="True" AutoGeneratingColumn="ColumnCreate"
                                ItemsSource="{Binding LabelTable,Mode=OneWay}" IsReadOnly="True" />

The code behind - breakpoint is not hit!
private void ColumnCreate(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
    GridViewColumn oCol = e.Column;
}

Note that I also have a post load process initiated by the ViewModel that loops through the created columns (in the first posting) that cannot format the textwrapping on the column header. It seems to me the ColumnCreate event will have the same problem - cannot get at the Column.Header.TextWrapping property to set it.
Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Mark
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or