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

Change RadGridView Column(content?)?

3 Answers 65 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 23 Sep 2010, 08:28 PM
Hello,

we have the evaluation version of Telerik and still testing the possibilitys.
How can i change the column head and content of a column when click on button in column header?

Szenario: We display data in a RadGrid. In some columns the ID of an entity is displayed. We want to have a button in the column head like the Filter Button. When click on the button the IDs in that row should be switched with the name according to the ID.  In the first step its not important if the data is loaded on demand or with the other data and column content is just switched.

I hope you can understand my Problem :)

Is there a possible solution?


Thank you.

3 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 24 Sep 2010, 06:10 AM
Hello,

 To modify the desired column header you can use Header property. Please check for example the third column in this demo. To modify the content of the data cells you have lots of options:

- You can change the column DataMemberBinding
- You can use IValueConverter for the column DataMemberBinding
- You can apply CellTemplate 
- You can load different templates conditionally using CellTemplateSelector
- Inherit from desired column type and return desired FrameworkElement directly similar to this post

Regards,
Vlad
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
0
Simon
Top achievements
Rank 1
answered on 24 Sep 2010, 05:30 PM
Thank you for your reply, it worked for me. I choosed to change the CellTemplate in code an trigger the event from a button in the head template.

Two more questions:
1. Can i create the DataTemplate as Controls without Loading it from XAMLReader?
2. What would you suggest is the best way to get the column(index) where the button is contained?

private void btn_changeColumn_Click(object sender, RoutedEventArgs e)
{
    var template = new DataTemplate();
      
    if (this.Tag == null)
    {
        template = (DataTemplate) XamlReader.Load(
            @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""> 
            <TextBlock Margin=""2"" Text=""{Binding WERK}"" /></DataTemplate>");
        var stackp = new StackPanel();
        stackp.Orientation = Orientation.Horizontal;
        var tb = new TextBlock();
        tb.Text = "LiefName";
        stackp.Children.Add(tb);
        var btn = new Button();
        btn.Click += new RoutedEventHandler(btn_changeColumn_Click);
        stackp.Children.Add(btn);
        gv_data.Columns[0].Header = stackp;
        this.Tag = "alt";
    }
    else
    {
        template = (DataTemplate)XamlReader.Load(
           @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""> 
            <TextBlock Margin=""2"" Text=""{Binding LIFNR}"" /></DataTemplate>");
        var stackp = new StackPanel();
        stackp.Orientation = Orientation.Horizontal;
        var tb = new TextBlock {Margin = new Thickness(3), Text = "LiefID"};
        stackp.Children.Add(tb);
        var btn = new Button {Margin = new Thickness(3), Width = 10};
        btn.Click += new RoutedEventHandler(btn_changeColumn_Click);
        stackp.Children.Add(btn);
        gv_data.Columns[0].Header = stackp;
        this.Tag = null;
    }
    gv_data.Columns[0].CellTemplate = template;
    var tempdata = gv_data.ItemsSource;
    gv_data.ItemsSource = null;
    gv_data.ItemsSource = tempdata;
}
0
Vlad
Telerik team
answered on 27 Sep 2010, 07:46 AM
Hi Simon,

 You can use separate UserControl in this DataTemplate and build your logic in the UserControl instead. 

Greetings,
Vlad
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
General Discussions
Asked by
Simon
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Simon
Top achievements
Rank 1
Share this question
or