Column Heading bindings in Q2 release

6 posts, 0 answers
  1. Keith
    Keith avatar
    88 posts
    Member since:
    May 2007

    Posted 29 Jun 2012 Link to this post

    Hi

    I've recently upgraded to the Q2 version of the controls and am now having an issue with binding for column headings - they do not seem to get bound and if I set a breakpoint on the binding it never gets called.

    XAML:
    <telerik:RadTreeListView x:Name="grd" Grid.Row="1"
                                FrozenColumnCount="1"
                                IsReadOnly="True">
     
        <telerik:RadTreeListView.ColumnGroups>
            <telerik:GridViewColumnGroup Name="Planned" Header="Planned" />
            <telerik:GridViewColumnGroup Name="Actual" Header="Actual" />
        </telerik:RadTreeListView.ColumnGroups>
         
        <telerik:RadTreeListView.Columns>
            <telerik:GridViewDataColumn UniqueName="colGeography" Width="200" Header="{Binding ColumnHeaders[0]}"/>
     
            <!-- Planned -->
            <telerik:GridViewDataColumn ColumnGroupName="Planned" Width="68" Header="{Binding ColumnHeaders[1]}"/>
            <telerik:GridViewDataColumn ColumnGroupName="Planned" Width="68" Header="{Binding ColumnHeaders[2]}"/>
             
            <!-- Actual -->
            <telerik:GridViewDataColumn ColumnGroupName="Actual" Width="68" Header="{Binding ColumnHeaders[3]}"/>
        </telerik:RadTreeListView.Columns>
    </telerik:RadTreeListView>

    And in the code behind:
    private void SetColumnHeadings()
    {
        ColumnHeaders.Clear();
     
        //Sample column headings
        ColumnHeaders.Add("");
        ColumnHeaders.Add("Plan 1");
        ColumnHeaders.Add("Plan 2");
        ColumnHeaders.Add("Actual 1");
    }
     
     
    public ObservableCollection<string> ColumnHeaders { get; set; }

    This used to work with the v1 controls. Any thoughts on how to work-around?

    Thanks
    Keith
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 29 Jun 2012 Link to this post

    Hi Keith, 

    Will it be possible to share a bit more details ? Where is the ColumnHeaders property defined ? 

    Kind regards,
    Maya
    the Telerik team

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

  3. DevCraft banner
  4. Keith
    Keith avatar
    88 posts
    Member since:
    May 2007

    Posted 29 Jun 2012 Link to this post

    Hi Maya

    Yes the ColumnHeaders is a property on the ViewModel which is bound from the view. The ColumnHeaders are populated from a database call but for this purpose they can be set up in the constructor i.e. hardcoded.

    To replicate the issue, just copy my original xaml into a page and then in the code behind add the ColumnHeaders property and the SetColumnHeaders method. In the Constructor / Load event, call the method and set the datacontext = this.
    If it's easier I can raise an incident and attach a sample solution.

    Thanks
    Keith
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 Jul 2012 Link to this post

    Hi Keith,

    Could you try defining the binding of the header as follows:

    <telerik:GridViewDataColumn ColumnGroupName="Planned" Width="68" Header="{Binding ColumnHeaders[1], Source={StaticResource MyViewModel}}"/>

    Do you get different result ?  

    All the best,
    Maya
    the Telerik team

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

  6. Keith
    Keith avatar
    88 posts
    Member since:
    May 2007

    Posted 03 Jul 2012 Link to this post

    Hi Maya

    Yes when I bind to a static resource the column headers appear although when I set the datacontext of the grid directly they no longer appear. Unfortunately I cannot use a static resource very easily since it doesn''t fit with the framework I am using. Is this a bug then?



    Thanks
    Keith
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 03 Jul 2012 Link to this post

    Hi Keith,

    The DataContext of the Header is of type object. So, you need to specify explicitly the source of the binding as it will not be the same as the one of the grid. In case you do not want to work with static resources, you can use a DataContextProxy as illustrated in this article.

    Kind regards,
    Maya
    the Telerik team

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

Back to Top
DevCraft banner