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

RADGRIDVIEW ROTATED COLUMNS TEXT HEADER LOADED ON THE FLY (DYNAMICALLY)

3 Answers 58 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Luis
Top achievements
Rank 1
Luis asked on 31 Mar 2011, 01:34 PM

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.

 

3 Answers, 1 is accepted

Sort by
0
Luis
Top achievements
Rank 1
answered on 31 Mar 2011, 03:54 PM
I solved problem 1 by putting the textblock inside a canvas.  In the xml I set the canvas minheight, and I changed the x y values to place the text at the desired position.  Also, I set the textblock size in the codebehind.  It works perfectly.  Now the only problem I have is the disappearing of the text when scrolling the page.  What I will try is to see if there is an event for the grid to detect the change in size and if so, I may need to reload the text.  In the mean time, as long as I don't post any other comments, that means I am still trying to find a solution so if you know how to solve the problem please, I will appreciate any comments.

Thanks in advance
0
Luis
Top achievements
Rank 1
answered on 31 Mar 2011, 04:35 PM
Placing the grid inside a stackpanel and the stackpanel inside a scrollbar and all inside a canvas, solved the problem.  Without the canvas the problem still is there.  Looks like the canvas is a separator where different rules may apply (good!).  but I did not find the way to add the srollbar to it so I added it to a stackpanel (smoke and mirrors but it works!).

Nobody replied but putting everything in writing helped me to refocus and so to find the solution.
0
Timothy
Top achievements
Rank 1
answered on 03 Apr 2011, 04:17 AM
This is exactly what I need. Can you please share your source code for this solution.

Thank you,
Tim
Tags
GridView
Asked by
Luis
Top achievements
Rank 1
Answers by
Luis
Top achievements
Rank 1
Timothy
Top achievements
Rank 1
Share this question
or