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

How to create style for GridViewDataColumn and replace his Header property

1 Answer 211 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Imran Aliyev
Top achievements
Rank 1
Imran Aliyev asked on 19 Oct 2010, 06:43 AM

I want to localize my GridView from xml file which has translation for my GridView headers.

I use next code:

   <Window.Resources>
        <Style TargetType="telerik:GridViewDataColumn">
            <Setter Property="Header" Value="someValue"/>
        </Style>
    </Window.Resources>
  
  
<Grid>
    <telerik:RadGridView HorizontalAlignment="Left" Name="radGridView1"  VerticalAlignment="Top"  >
  
    </telerik:RadGridView>
  
</Grid>


and my code behind:
public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();
 
        var lst = new List<Foo>
                      {
                          new Foo() {CompanyName = "Burkinafaso", Phone = "6666"},
                          new Foo() {CompanyName = "Reebok", Phone = "555"}
                      };
 
        radGridView1.SetBinding(RadGridView.ItemsSourceProperty, new Binding {Source = lst});
    }
}
 
public class Foo
{
    public string CompanyName { get; set; }
    public string Phone { get; set; }
 
}

 
But Headers not change. Why I cannot change headers with this approach?
 I am planning to bind TextBlock to the XmlNode value and get appropriate translation by Header system name



1 Answer, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 21 Oct 2010, 03:01 PM
Hi Imran,

This behavior occured because you create a style that targets at GridViewDataColumn, but this is not allowed because GridViewColumns are not visual objects. If you want to apply changes to the headers you should create a style that targets at GridViewHeaderCell. Having in mind your localization requirements the better approach is to create a DataTemplate and apply it to the Header property of GridViewDataColumn.
I have prepared an example for you that demonstrates this approach.

Best wishes,
Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Imran Aliyev
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Share this question
or