I have had to use custom headers for a few columns in order to implement wrapping:
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding QualityOpportunities}"
Width
=
"125"
TextWrapping
=
"Wrap"
>
<
telerik:GridViewDataColumn.Header
>
<
Grid
>
<
TextBlock
Text
=
"Number of Quality Opportunities"
TextWrapping
=
"Wrap"
HorizontalAlignment
=
"center"
/>
</
Grid
>
</
telerik:GridViewDataColumn.Header
>
</
telerik:GridViewDataColumn
>
However when I export the grid the column header turns into "System.Windows.Controls.Grid" instead of using the text of the text block. How can I get the column header to export correctly?
Thank you!
5 Answers, 1 is accepted
You may take a look at this forum thread on the same topic. There is a sample application, which you may download and review.
Please let me know in case you have any further questions.
Didie
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
I'm not sure if this is how that other thread handles it but this is what worked for me (please let me know if this is a horrible hack or if I am doing it correctly):
Private
Sub
RadGridViewEvidenceBasedMedicine_ElementExporting(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.Windows.Controls.GridViewElementExportingEventArgs)
Handles
RadGridViewEvidenceBasedMedicine.ElementExporting
If
e.Context
Is
Nothing
OrElse
e.Context.ToString.Trim <>
"Telerik.Windows.Controls.GridViewDataColumn"
OrElse
e.Value
Is
Nothing
Return
End
If
If
e.Context.datamemberbinding.path.path =
"QualityOpportunities"
and e.Value.ToString.Trim =
"System.Windows.Controls.Grid"
e.Value =
"Number Of Quality Opportunities"
ElseIf
e.Context.datamemberbinding.path.path =
"QualityOpportunitiesWithCompliance"
and e.Value.ToString.Trim =
"System.Windows.Controls.Grid"
e.Value =
"With Compliance"
ElseIf
e.Context.datamemberbinding.path.path =
"ComplianceRate"
and e.Value.ToString.Trim =
"System.Windows.Controls.Grid"
e.Value =
"Compliance Rate"
End
If
End
Sub
This is fine, the only problem is that the value is hard-coded.
In the forum the export is done almost the same way except for the value used. There it is explained that you need just to set the Text of the e.Value in the ElementExporting event like so:
if
(e.Value !=
null
&&
e.Value.GetType() ==
typeof
(TextBlock
))
e.Value = (e.Value
as
TextBlock).Text
;
It is up to you what you prefer.
Best wishes,
Didie
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
Your suggestion is definitely more efficient and I would prefer to use that however it does not work...
For vb.net I believe the conversion would be:
If
e.Value IsNot
Nothing
AndAlso
e.Value.
GetType
()
Is
GetType
(TextBlock)
Then
e.Value = TryCast(e.Value, TextBlock).Text
End
If
The problem is that for the columns where the type is displayed as the header instead of the header text in the text block the Type is being returned as {System.Windows.Controls.Grid} and not TextBlock.
Once again, here is the column in question:
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding QualityOpportunities}"
Width
=
"125"
TextWrapping
=
"Wrap"
>
<
telerik:GridViewDataColumn.Header
>
<
Grid
>
<
TextBlock
Text
=
"Number of Quality Opportunities"
TextWrapping
=
"Wrap"
HorizontalAlignment
=
"center"
/>
</
Grid
>
</
telerik:GridViewDataColumn.Header
>
</
telerik:GridViewDataColumn
>
The header text that gets displayed is: "System.Windows.Controls.Grid".
Thanks again!
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding QualityOpportunities}"
Width
=
"125"
TextWrapping
=
"Wrap"
>
<
telerik:GridViewDataColumn.Header
>
<
TextBlock
Text
=
"Number of Quality Opportunities"
TextWrapping
=
"Wrap"
HorizontalAlignment
=
"center"
/> </
telerik:GridViewDataColumn.Header
>
</
telerik:GridViewDataColumn
>
Not sure why I had them there in the first place, must have copied from another example. Now it works perfectly with your code. Thank you!