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

[Solved] binding header of the gridviewdatacolumn

4 Answers 478 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
meena
Top achievements
Rank 1
meena asked on 28 Jul 2011, 12:08 PM
Hi,

The telerik rad gridview is binded to items source and also has selectedItem binding in MVVM pattern. If I need to change the Header of a particulat GridviewDatacolumn, Binding the header to a property is not displaying the value. Using the normal binding is

Header="{Binding Path=HeaderName}" not  working. Should anything else is tobe added?

4 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 28 Jul 2011, 12:11 PM
Hi Meena,

 
You may take a look at the following forum thread for further information.


Regards,
Vanya Pavlova
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
meena
Top achievements
Rank 1
answered on 16 Aug 2011, 11:01 AM
hi,
The solution provided in the above forum is not working, Am missing anything??

<TextBlock x:Name="testOIL" Text="{Binding OilHeader}" Grid.Row="0"/>

<telerikGrid:RadGridView x:Name="DataLog" RowStyle="{StaticResource GridViewStyle}" IsReadOnly="True" AutoGenerateColumns="False" Grid.Row="1" CanUserFreezeColumns="False" 
VerticalAlignment="Top" ItemsSource="{Binding Logs, Mode=TwoWay}" SelectedItem="{Binding LogEntry}" IsSynchronizedWithCurrentItem="true">

<telerikGrid:RadGridView.Columns>
<telerikGrid:GridViewDataColumn Width="Auto" IsReadOnly="True" DataMemberBinding="{Binding OilPressure}">
<telerikGrid:GridViewDataColumn.Header>
<TextBlock Text="{Binding Path=Text, ElementName=testOIL}" />
</telerikGrid:GridViewDataColumn.Header>
</telerikGrid:GridViewDataColumn>
</telerikGrid:RadGridView.Columns>
</telerikGrid:RadGridView>
0
Vanya Pavlova
Telerik team
answered on 16 Aug 2011, 01:09 PM
Hello Meena,

 


You should keep in mind that the DataContext of the header is not the same as the DataContext of the grid. You have to explicitly of the Header to be the one of grid and afterwards, you may bind the Text property directly to the one defined there:

<telerik:GridViewDataColumn DataMemberBinding="{Binding Property1}">
                    <telerik:GridViewDataColumn.Header>
                        <TextBlock Width="100" Text="{Binding  MyCustomHeaderProperty,Source={StaticResource MyViewModel}}" Foreground="Red"/>
                        </telerik:GridViewDataColumn.Header>
                    </telerik:GridViewDataColumn>


Here MyCustomHeaderProperty is a property of your ViewModel which holds some value, which should be displayed. For example if you want to bind the header outside of the grid you may use the element name binding as proposed in the following online help article.


Greetings,
Vanya Pavlova
the Telerik team

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

0
meena
Top achievements
Rank 1
answered on 17 Aug 2011, 12:32 PM
Thanks :) , It worked ! the MyCustomHeaderProperty link was really helpful.
Tags
GridView
Asked by
meena
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
meena
Top achievements
Rank 1
Share this question
or