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

Column Style?

1 Answer 111 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 05 Feb 2010, 12:44 AM
Is there a way to either set the header to be vertical or to style a column in XAML.  I have a old  vb6 Flexgrid control that I need to replicate and I can do all of it in vb.net code -- but I wanted to style it to be grey(ghostwhite) and set the width and if possible define the static parts all in XAML and then just update the data parts in code
Private Sub BuildGrid(ByRef g As Telerik.Windows.Controls.RadGridView, ByRef d As IBIDData.Client) 
        Dim dt As New DataTable(g.Name) 
        dt.Columns.Add(0) 
        dt.Columns.Add(1) 
        Select Case g.Name 
            Case "grd1" 
                '// This is done after the call - grd1.Columns(0).Width = 80 
                '//                               grd1.Columns(0).Background = System.Windows.Media.Brushes.GhostWhite 
                '//                               grd1.Columns(1).Width = 68 
                dt.Rows.Add(New Object() {"Author", d.FieldStr(0, "Author")}) 
                dt.Rows.Add(New Object() {"Vendor", d.FieldStr(0, "Vendor")}) 
                dt.Rows.Add(New Object() {"Dept", d.FieldStr(0, "DptCode")}) 
                dt.Rows.Add(New Object() {"Publisher", d.FieldStr(0, "Publisher")}) 
                dt.Rows.Add(New Object() {"Pub. Date", d.FieldStr(0, "PubDate")}) 
                dt.Rows.Add(New Object() {"Last Sold", d.FieldStr(0, "LastDateSold")}) 
                dt.Rows.Add(New Object() {"Last Recv", d.FieldStr(0, "LastInvoiceDate")}) 
            Case "grd2" 
                dt.Rows.Add(New Object() {"List", d.FieldStr(0, "ListPrice")}) 
                dt.Rows.Add(New Object() {"Binding", d.FieldStr(0, "BookType")}) 
                dt.Rows.Add(New Object() {"Category 1", d.FieldStr(0, "Cat1")}) 
                dt.Rows.Add(New Object() {"Category 2", d.FieldStr(0, "Cat2")}) 
                dt.Rows.Add(New Object() {"Misc. 1", d.FieldStr(0, "Misc1")}) 
                dt.Rows.Add(New Object() {"Misc. 2", d.FieldStr(0, "Misc2")}) 
                dt.Rows.Add(New Object() {""""}) 
            Case "grd3" 
                dt.Rows.Add(New Object() {"Cost", d.FieldStr(0, "CostPrice")}) 
                dt.Rows.Add(New Object() {"Sell", d.FieldStr(0, "SellPrice")}) 
                dt.Rows.Add(New Object() {"Net", d.FieldStr(0, "NetPrice")}) 
                dt.Rows.Add(New Object() {"Retd YTD", d.FieldStr(0, "YTDReturns")}) 
                dt.Rows.Add(New Object() {"Retd LYR", d.FieldStr(0, "PYRReturns")}) 
                dt.Rows.Add(New Object() {"All Retd", d.FieldStr(0, "AllReturns")}) 
                dt.Rows.Add(New Object() {"All Sales", d.FieldStr(0, "AllSales")}) 
            Case "grd4" 
                dt.Rows.Add(New Object() {"On Hand", d.FieldStr(0, "OnHand")}) 
                dt.Rows.Add(New Object() {"TBO", d.FieldStr(0, "")}) 'fnTBO 
                dt.Rows.Add(New Object() {"On Ord", d.FieldStr(0, "")}) 'fnORD 
                dt.Rows.Add(New Object() {"SPO", d.FieldStr(0, "")}) 'fnSPOSOLD 
                dt.Rows.Add(New Object() {"TBR", d.FieldStr(0, "")}) 'fnTBR 
                dt.Rows.Add(New Object() {"Minimum", d.FieldStr(0, "Minimum")}) 
                dt.Rows.Add(New Object() {"Reorder", d.FieldStr(0, "Reorder")}) 
 
        End Select 
        g.ItemsSource = dt 
    End Sub

<UserControl x:Class="InvGrid" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"   
    Height="Auto" Width="Auto" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    <UserControl.Resources> 
        <ResourceDictionary> 
            <Style TargetType="telerik:GridViewRow" x:Key="RowStyle"
                <Setter Property="MinHeight" Value="18"/> 
                <Setter Property="FontSize" Value="14"/> 
                <Setter Property="Foreground" Value="Black"/> 
            </Style> 
            <ResourceDictionary.MergedDictionaries> 
                <ResourceDictionary Source="Dictionary1.xaml"/> 
            </ResourceDictionary.MergedDictionaries> 
        </ResourceDictionary> 
    </UserControl.Resources> 
    <Grid x:Name="Container"
        <Grid Margin="0,0,0,0" Name="Grid1"
            <Grid.ColumnDefinitions> 
                <ColumnDefinition x:Name="Column1" MinWidth="200"    /> 
                <ColumnDefinition x:Name="Column2" MinWidth="200"  /> 
                <ColumnDefinition x:Name="Column3" MinWidth="200"  /> 
                <ColumnDefinition x:Name="Column4" MinWidth="200" /> 
                <ColumnDefinition x:Name="Column5" MinWidth="200"  /> 
            </Grid.ColumnDefinitions> 
            <telerik:RadGridView Name="grd1" RowStyle="{StaticResource RowStyle}" Background="White" RowIndicatorVisibility="Collapsed"  IsFilteringAllowed="False" Grid.Column="1" Height="198"  Width="200" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSelect="False" CanUserSortColumns="False" CanUserFreezeColumns="False" CanUserDeleteRows="False" ShowColumnHeaders="False" ShowGroupPanel="False" FontFamily="Microsoft San Serif" FontSize="13" IsTabStop="False" IsHitTestVisible="False" BorderThickness="1" ShowGroupFooters="False" ScrollMode="RealTime"  MinHeight="26" BorderBrush="Black" Foreground="Black" ClipToBounds="False" /> 
            <telerik:RadGridView Name="grd2" RowStyle="{StaticResource RowStyle}" Background="White" RowIndicatorVisibility="Collapsed"  IsFilteringAllowed="False" Grid.Column="2" Height="158"   Width="150" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSelect="False" CanUserSortColumns="False" CanUserFreezeColumns="False" CanUserDeleteRows="False" ShowColumnHeaders="False" ShowGroupPanel="False" FontFamily="Microsoft San Serif" FontSize="13" IsTabStop="False" IsHitTestVisible="False" BorderThickness="1" ShowGroupFooters="False" ScrollMode="RealTime"  MinHeight="26" BorderBrush="Black" /> 
            <telerik:RadGridView Name="grd3" RowStyle="{StaticResource RowStyle}" Background="White" RowIndicatorVisibility="Collapsed"  IsFilteringAllowed="False" Grid.Column="3" Height="198"   Width="150" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSelect="False" CanUserSortColumns="False" CanUserFreezeColumns="False" CanUserDeleteRows="False" ShowColumnHeaders="False" ShowGroupPanel="False" FontFamily="Microsoft San Serif" FontSize="13" IsTabStop="False" IsHitTestVisible="False" BorderThickness="1" ShowGroupFooters="False" ScrollMode="RealTime"  MinHeight="26" /> 
            <telerik:RadGridView Name="grd4" RowStyle="{StaticResource RowStyle}" Background="White" RowIndicatorVisibility="Collapsed"  IsFilteringAllowed="False" Grid.Column="4" Height="198"   Width="150" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSelect="False" CanUserSortColumns="False" CanUserFreezeColumns="False" CanUserDeleteRows="False" ShowColumnHeaders="False" ShowGroupPanel="False" FontFamily="Microsoft San Serif" FontSize="13" IsTabStop="False" IsHitTestVisible="False" BorderThickness="1" ShowGroupFooters="False" ScrollMode="RealTime"  MinHeight="26" /> 
        </Grid> 
    </Grid> 
</UserControl> 

1 Answer, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 08 Feb 2010, 12:57 PM
Hi Mark,

The GridViewDataColumn class has a property HeaderCellStyle which allows you to controls the style of header cells. You can find more information about styling header cells in our online documentation .

You can also create a vertical header by supplying a custom Header content and using LayoutTransform:

<telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}">
    <telerik:GridViewDataColumn.Header>
        <Grid>
            <Grid.LayoutTransform>
                <RotateTransform Angle="90"/>
            </Grid.LayoutTransform>
            <TextBlock Text="My Vertical Header"/>
        </Grid>
    </telerik:GridViewDataColumn.Header>
</telerik:GridViewDataColumn>

Do not hesitate to write if you have more questions, we will be glad to help you.

Sincerely yours,
Milan
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Milan
Telerik team
Share this question
or