In a rad gridview control I'm displaying tabular data. The table has four rows only but it may have n number of columns so i I'm generating them dynamically (I assigned a datatable to the itemssource and whatever columns the datatable has, that's what the datagrid will display). The problem is that I want to rotate the column headings (my client, and I can understand because the table will have an average of 40 columns.... to wide for the user to scroll left-right to find a column). I managed to use a style template with this code in the xaml file:
<
UserControl.Resources>
<Style x:Name="GV" TargetType="telerik:GridViewHeaderCell">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="telerik:GridViewHeaderCell">
<Border Height="150" Width="40">
<TextBlock Loaded="TextBlock_Loaded" HorizontalAlignment="Center" MinWidth="150" VerticalAlignment="Center" >
<TextBlock.RenderTransform>
<TransformGroup>
<RotateTransform Angle="270" CenterX="0.5" CenterY="0.5" />
<TranslateTransform X="60" Y="100"/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<MatrixTransform x:Key="RenderTransform1" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<sdk:Label Content="Data By Quarter" Height="28" HorizontalAlignment="Left" Margin="30,30,0,0" Name="Label1" VerticalAlignment="Top" Width="120" FontWeight="Bold" FontSize="16" FontFamily="Arial" />
<telerik:RadGridView HorizontalAlignment="Left" Margin="30,50,0,0" Name="QuarterlyGridView" VerticalAlignment="Top"
CellLoaded="QuarterlyGridView_CellLoaded"
/>
</Grid>
</
UserControl>
The cell loaded event is what actually loads the text in the headings. It rotates the text but I have these to problems:
1- When rotating, the text length after rotating keeps the original column width
2- When scrolling to the right and then back to the left, the text disappears like it was wiped out
my code for the cell loaded and text block loaded events are as follows:
Private
Sub QuarterlyGridView_CellLoaded(ByVal sender As System.Object, ByVal e As Telerik.Windows.Controls.GridView.CellEventArgs)
Dim gridView As RadGridView = DirectCast(sender, RadGridView)
Dim cell As GridViewCell = TryCast(e.Cell, GridViewCell)
For Each mycol As GridViewColumn In gridView.Columns
mycol.HeaderCellStyle =
TryCast(Me.Resources("GV"), Style)
Next
End Sub
Private Sub TextBlock_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Try
Dim TxtBlock As TextBlock = TryCast(sender, TextBlock)
If n < MyCols.Count Then
TxtBlock.Text = MyCols(n)
n = n + 1
End If
Catch ex As Exception
Dim str As String = ex.Message
End Try
End Sub
Can these problems be solved? Any suggestions?
Thanks in advance.