GridViewColumnGroup

7 posts, 1 answers
  1. Matthias Bibo
    Matthias Bibo avatar
    72 posts
    Member since:
    Mar 2010

    Posted 11 Jan 2012 Link to this post


    Hi,

    I was wondering if it is somehow possible to change the GridViewColumnGroup Header property at runtime in code behind.
    I tried accessing the GridViewColumnGroups via x:Name in codebehind, but they are always null.

    Binding the Header didn't work either.
    Is there a way to change the header Content at runtime, for example writing the current month to the header?

    Thanks & Best Regards,
    Matthias
  2. Answer
    Nick
    Admin
    Nick avatar
    593 posts

    Posted 11 Jan 2012 Link to this post

    Hello,

    There are a couple of ways that this can be implemented. 
    You can define your own HeaderTemplate for the ColumnGroup where you can use a TextBlock and Bind the text that you want to change. 

    <telerik:GridViewColumnGroup  Name="Vehicle" >
                        <telerik:GridViewColumnGroup.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding HEADER_TEXT}"/>
                            </DataTemplate>
                        </telerik:GridViewColumnGroup.HeaderTemplate>
                    </telerik:GridViewColumnGroup>

    You can also use the ColumnGroups collection of the GridView to manipulate the headers. Note however that for the time being the UI will not be notified about the change in the header, so you will have to apply a simple workaround. 
    this.RadGridView.ColumnGroups[DESIRED_HEADER_NAME].Header = HEADER_TEXT ;
     
     
                var columnGroup = new GridViewColumnGroup();
                this.RadGridView.ColumnGroups.Add(columnGroup);
                this.RadGridView.ColumnGroups.Remove(columnGroup);
    The notification logic is currently being implemented and will be available in one of our next internal builds.

    Hope this helps! 

    All the best,
    Nik
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. vinay Theethira
    vinay Theethira avatar
    35 posts
    Member since:
    Mar 2010

    Posted 12 Jun 2012 Link to this post

    Hi,

    Can you please explain me how i can bind the values from viewmodel to gridviewcolumngroup headerTemplate Dynamically.
  5. Arnaud
    Arnaud avatar
    17 posts
    Member since:
    Mar 2013

    Posted 30 Sep 2015 Link to this post

    Hello,

    Facing the same issue​! Please help us, and give us the answer that Vinay is still waiting for... 

    Arnaud.

  6. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 05 Oct 2015 Link to this post

    Hello Arnaud,

    Can you please take a look at the GroupHeaderTemplateSelector online demo, as it demonstrates how this can be achieved?

    Hope this helps.

    Best Regards,
    Stefan
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  7. Arnaud
    Arnaud avatar
    17 posts
    Member since:
    Mar 2013

    Posted 06 Oct 2015 in reply to Stefan X1 Link to this post

    Hello Stefan,

    I'm afraid you did not get the question. I'm speaking about <telerik:GridViewColumnGroup> which are part of <telerik:RadGridView.ColumnGroups>. Nothing to do with groupings of rows.... but with ​merged columns headers!

     Regards,

    Arnaud.

     

     

  8. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 09 Oct 2015 Link to this post

    Hi Arnaud,

    Please excuse me for the misunderstanding.

    A possible approach for this scenario, is to define the needed DataTemplate and set it at run-time through the HeaderTemplate property of GridViewColumnGroup.
    <DataTemplate x:Key="ColumnGroupHeaderTemplate">
        <TextBox Text="Modified"/>
    </DataTemplate>
    var cg = this.myGrid.ColumnGroups[0];
    cg.HeaderTemplate =
        this.Resources["ColumnGroupHeaderTemplate"] as DataTemplate;

    Regards,
    Stefan X1
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner