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

Column Heading bindings in Q2 release

5 Answers 54 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Keith
Top achievements
Rank 1
Keith asked on 29 Jun 2012, 10:38 AM
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

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 29 Jun 2012, 02:12 PM
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 >>

0
Keith
Top achievements
Rank 1
answered on 29 Jun 2012, 02:53 PM
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
0
Maya
Telerik team
answered on 02 Jul 2012, 07:03 AM
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 >>

0
Keith
Top achievements
Rank 1
answered on 03 Jul 2012, 07:14 AM
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
0
Maya
Telerik team
answered on 03 Jul 2012, 08:44 AM
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 >>

Tags
TreeListView
Asked by
Keith
Top achievements
Rank 1
Answers by
Maya
Telerik team
Keith
Top achievements
Rank 1
Share this question
or