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

Databinding GridViewDataColumn and the group-by functionality

3 Answers 67 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 30 Sep 2016, 01:14 PM

Hello group, 

Question: I have a GridViewDataColumn. The Header property has been bind to an property in the ViewModel. If you now in the UI drag the column header to the group-by bar the Grid will display the name of the group-by as: [DataContextName].[PropertyName] instead of the (string) value of the property of the binding. 

I have tried to use an converter to collect the string form the resource file but this does not work either. 

Help would be appriciated. 

Richard

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 04 Oct 2016, 10:12 AM
Hello Richard,

Would it be possible for you to demonstrate the exact steps to reproduce such behavior, as I am not able to do so locally? Sharing some code would also be quite useful.

Thanks in advance for your cooperation.

Regards,
Stefan X1
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Richard
Top achievements
Rank 1
answered on 07 Oct 2016, 11:46 AM

In my XAML I bind the property ContentTemplate to the property ChargeCodeColumnHeader in my Viewmodel.
XAML looks like this:

<telerik:GridViewDataColumn DataMemberBinding="{Binding PerformedActivityOverviewItem.ChargeCode}"
 Width="100">
 <telerik:GridViewDataColumn.HeaderCellStyle>
 <Style TargetType="telerik:GridViewHeaderCell">
 <Setter Property="ContentTemplate">
 <Setter.Value>
 <DataTemplate>
 <TextBlock Text="{Binding DataContext.ChargeCodeColumnHeader, ElementName=Root}"
 TextWrapping="Wrap" />
 </DataTemplate>
 </Setter.Value>
 </Setter>
 </Style>
 </telerik:GridViewDataColumn.HeaderCellStyle>
</telerik:GridViewDataColumn>

The Viewmodel property:

public string ChargeCodeColumnHeader
{
    get
       {
         return (AddOnMedicationOnly) ? CommonResources.ZINumberColumn :   CommonResources.WrappedChargeCodeColumn;
       }
}

Now the page the column header displays the name correct (taken from the resource file). However if you drag the column header to the group-by banner you will see:
PerformedActivityOverviewItem.ChargeCode
this is the Datacontext.property name instead of the value of ChargeCodeColumnHeader.

How can I display the value of ChargeCodeColumnHeader property?

Thanks in advance.

0
Stefan
Telerik team
answered on 12 Oct 2016, 06:50 AM
Hello Richard,

The reported behavior is due to the DataContext of the column header. It is not the same as the one of the column and needs to be explicitly set. Please take a look at this forum thread for further reference.

Best Regards,
Stefan X1
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Richard
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Richard
Top achievements
Rank 1
Share this question
or